1.

What is the size of empty class in C++?

Answer»

#include <iostream>using namespace STD;class MyClass{};int main() { COUT<<sizeof(MyClass)<<"\n"; }// Output:// 1

The size of an empty class in C++ is 1 byte. The reason BEHIND this is to make SURE that 2 different objects have 2 different addresses. If they have the same addresses then there is no way to differentiate whether two objects are the same or different. It all boils down to the identity of the object.



Discussion

No Comment Found