top of page

why size of empty class object contains 1 byte in c++?

  • Writer: prashant raj
    prashant raj
  • Mar 10, 2021
  • 1 min read

Updated: May 2, 2021



Compiler allocate 1 byte of memory of empty class object for unique address identification. So, if a class have multiple objects they can have different unique memory location.

Means for differentiate the objects of empty class compiler allocate 1 byte of memory.

Size of Empty Class in C++ with virtual function :

If empty class contains virtual function then size of empty class object will be 4 byte because of virtual pointer.

Note: Every virtual function contains one virtual pointer.

Comentarios


Drop Me a Line, Let Me Know What You Think

Thanks for submitting!

© 2023 by Train of Thoughts. Proudly created with Wix.com

bottom of page