The standard does not allow objects of size 0 since that would make it possible for two distinct objects to have the same memory address. That’s why even empty classes must have a size of (at least) 1 byte.
Example,
#include<iostream>
using namespace std;
class Test
{
//empty class
};
int main()
{
cout << sizeof(Test);
return 0;
}
The standard does not allow objects of size 0 since that would make it possible for two distinct objects to have the same memory address. That’s why even empty classes must have a size of (at least) 1 byte.
Example,
Output: 1
need an explanation for this answer? contact us directly to get an explanation for this answer