GfG QA is closing soon... Please refer PRACTICE or GfG now on wards !!

What is the output and why?

#include<bits/stdc++.h>
struct A{

};
int main()
{
        A obj;
        printf("%d",sizeof(obj));
    return 0;
}

 

asked Nov 26, 2015 by passion34

1 Answer

Size of an empty class is not zero. It is 1 byte generally. It is nonzero to ensure that the two different objects will have different addresses. 
Check more examples at : http://www.geeksforgeeks.org/why-is-the-size-of-an-empty-class-not-zero-in-c/

answered Nov 26, 2015 by Swanky

btw it is structure.

...