Interview Question
Country: United States
size is 16
I am trying so see what happens by commenting different parts of the question.
When it is empty class. commenting virtual destructor and 2 ints and a char. it gives 1. (Its simple)
now including the char in the class, rest of the part is same. Then it gives 1. (Again justified)
But if we include the virtual destructor then size becomes 8. If that because of padding ?? or anything else!! Size due to virtual destructor is 4. 2 ints (4*2).
But size of char suddenly changes from 1 to 4?? Is it for padding. I think so. Correct me if I am wrong.
can someone plz tell me what does 4 byte allignment in 32bit system mean.
eg :
struct
{
char a;
char b;
}
will it take 8 byte or 4 byte after padding
So what is the size of the class if it is
Class A
{
Public:
A();
Virtual ~A();
char a;
Char b;
Int c;
}
sizeof(A) = 16 = 2 * sizeof(int) + sizeof ( pointer to virtual table ) + [ sizeof(char) + 3 padding]
- adrian.chitescu90 August 29, 2012