Student Interview Question
Software Engineer in TestsCountry: India
Interview Type: Written Test
Depending on the architecture definitions of double, int, etc.... each member is a different value potentially but let's assume a 32bit architecture:
double = 4Bytes
char = 1 Byte
int = 4 Byte
The structure isn't listing any option for packing and you cannot access (unless you have a funny architecture that allows it) access of doubles or ints on a non-word alignment (0,0x4, 0x8, 0xc). I believe the answer will be 12 Bytes.
in interviews easiest is to say " it depends" and ask about the architecture being used.
Most of the Time size of the structure is not equal to the sum of the size of all its elements.It is because of Padding Space added to the element with respect to the largest element.
Example:
In the above question size of the structure is 16 bytes.
- kamleshbhalui September 07, 2017Here size of largest Element is 8 bytes.
when another element comes another slot of 8 bytes is allocated and then a character element takes 1 bytes and integer takes 4 bytes.In this slot, 3 more bytes are remaining if other elements came which size is less than or equal to 3 bytes allocated to that slot otherwise another 8 bytes slot is allocated.