Answer & Solution
Answer: Option D
Solution:
In C++, the size of a structure is determined by the sum of the sizes of its individual members, taking into account padding for alignment. The
Employee structure consists of three members: an integer
id, an array of characters
name of size 20, and a float
salary.
The size of an integer is typically 4 bytes, the size of a float is also typically 4 bytes, and the size of each character in the array depends on the character set being used (usually 1 byte per character). However, due to memory alignment requirements, additional padding may be added after the
name array to ensure proper alignment of subsequent members.
So, the calculation of the structure size would be:
int id: 4 bytes
char name[20]: 20 bytes
Padding to align
salary to the next 4-byte boundary (assuming 4-byte alignment)
float salary: 4 bytes
Total: 4 bytes (id) + 20 bytes (name) + 4 bytes (padding) + 4 bytes (salary) = 32 bytes.
Therefore, the correct answer is
Option D: 32 bytes.