Memory Allocation for Object of Class


Once you define class it will not allocate memory space for the data member of the class. The memory allocation for the data member of the class is performed separately each time when an object of the class is created.
Since member functions defined inside class remains same for all objects, only memory allocation of member function is performed at the time of defining the class.
Thus memory allocation is performed separately for different object of the same class. All the data members of each object will have separate memory space.
The memory allocation of class members is shown below:

     
Memory Allocation

Hence data member of the class can contain different value for the different object, memory allocation is performed separately for each data member for different object at the time of creating an object.
Member function remains common for all object. Memory allocation is done only once for member function at the time of defining it.

Download Projects


Download Programs