Bloomberg LP Interview Question
Software Engineer / DevelopersCountry: United States
Interview Type: In-Person
The size of empty class is always One . This is because the compiler insert a char, anyhow he need a memory address to identify a class
The following methods are generated:
class C
{
C();
~C();
C(const C & );
C& operator = (const C &);
C& operator *();
C* operator &();
};
I believe this is correct because the code snippet given defines the class C but does not instantiate it. No space is allocated.
class C{};
C* pc = new C;
int n = sizeof(C);
n = sizeof(*pc);
I don't know why but n was 1.
Still the member methods are created and they are not counted as a size.
empty class size is 1.
- kbhaskarkotha March 14, 2012