Consider the following C declaration:
struct {
short x[5];
union {
float y;
long z;
} u;
)t;
Assume that the objects of the type short, float and long occupy bytes, bytes and bytes, respectively. The memory requirement for variable , ignoring alignment consideration, is:
View worked solution
Answer: C
To find the memory requirement for the structure variable t, we calculate the sizes of its individual members, ignoring any alignment constraints:
- Member
x: It is an array of 5 elements of typeshort. - Member
u: It is aunioncontaining afloatand along. Since members of a union share the same memory space, the size of the union is determined by its largest member:
Since t is a struct, its total size (ignoring alignment) is the sum of the sizes of its members:
Therefore, the correct option is C.
Free practice · Your answers on this page are not saved.
