Discussion
Consider the following C declaration
struct {
short s[5];
union {
float y;
long z;
}u;
}t;
Assume that the objects of the type short, float and long occupy 2 bytes, 4 bytes and 8 bytes, respectively. The memory requirement for variable t, ignoring alignment consideration, is
Answer: B
Correct answer: 18 bytes
The array contributes \(5 \times 2 = 10\) bytes, and the union takes the size of its largest member, \(\max(4, 8) = 8\). The structure sums them, giving 18 bytes. The union’s members overlap, which is why the float costs nothing extra beyond the long.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development