-
Consider the following C declaration
struct {
short s [5]
union {
float y;
long z;
} u;
} t;
Assume that objects of the type short, float and long occupy 2 byte, 4 byte and 8 byte, respectively. The memory requirement for variable t, ignoring alignment considerations, is
-
- 22 byte
- 14 byte
- 18 byte
- 10 byte
- 22 byte
Correct Option: C
The amount of memory required to store a structure variable is the sum of the sizes of all its members. But in the case of union, the amount of memory required is the amount required by its largest member. Therefore u, which is a union member of the struct, occupies only 8 bytes of memory, because the largest memory is 8 bytes consumed by long z;. Another member in the struct is short s [5], this will occupy 10 bytes of memory (2 bytes x 5).