Do member functions of a class occupy memory?

Suppose a class contains a member function that has 2 local variable . Will the size of the the local variables be counted in the calculation of the size of class? if not , why ?

Hello @Anchal,

The class is only the definition and it’s size is counted by it’s LOC i.e. Line of Code.
The size is assigned to it’s object at memory, when it is declared.

No,
The size of local variables does not affects the size of object as it’s size is independent of local variable.
The local variable of member function would get memory in the stack at the time of function execution.

Hope, this would help.
Give a like, if you are satisfied.

A class without an object requires no space allocated to it. The memory allocation takes place only when you create objects because the objects is what implements the contents of the class. So to an object of an empty class, 1 byte is allocated by compiler, for it’s unique address identification. If a class have multiple objects they can have different unique memory location. When you create new class, it will call an allocation function . This function can have different implementations. This depends on the object oriented programming language, the language version, libraries, and configuration.