Consider the following C declaration. Assume that objects of data type short, float and long occupy 2 bytes, 4 bytes and 8 bytes respectively. What is the…
Consider the following C declaration. Assume that objects of data type short, float and long occupy 2 bytes, 4 bytes and 8 bytes respectively. What is the memory requirement for variable t?
struct {
short a[5];
union {
float v;
long z;
} u;
} t;
Show answerHide answer
Correct answer: (B) 18 bytes
Explanation
short a[5] takes 5 × 2 = 10 bytes. The union takes the size of its largest member, long, which is 8 bytes. Total = 10 + 8 = 18 bytes, ignoring alignment padding.