Object Oriented Programming

Here is the code that I wrote to print the size of the object of the class:- https://ide.codingblocks.com/s/453170, but the thing is the total memory space occupied by class car is 46, but the object size is coming out to be 48, how so? Please specify.

hello @Sakshi2004

There are many factors that decide the size of an object of a class in C++.

  1. Size of all non-static data members
  2. Order of data members
  3. Byte alignment or byte padding
  4. Size of its immediate base class
  5. The existence of virtual function(s) (Dynamic polymorphism using virtual functions).
  6. Compiler being used
  7. Mode of inheritance (virtual inheritance)

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.