Question 17Asked in DSSSB TGT Computer Science (Technical), 8 Aug 2021, Shift 2

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;
  1. A22 bytes
  2. B18 bytes
  3. C24 bytes
  4. D10 bytes
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.

From DSSSB TGT Computer Science PYQ (Technical), 8 Aug 2021, Shift 2

This is question 17 of DSSSB TGT Computer Science PYQ (Technical), 8 Aug 2021, Shift 2. See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.