GATE Computer ScienceVery hardGATE CSE · TCS

On a machine where char needs 1-byte, short 2-byte and int 4-byte alignment (each member at the next offset divisible by its own size, and the structure padded to a multiple of its largest member's alignment), what is sizeof(struct S) for struct S { char a; int b; char c; short d; char e; };

  1. A. 12
  2. B. 14
  3. C. 10
  4. D. 16

Correct answer: D. 16

Offsets: a 0, b 4–7, c 8, d 10–11, e 12; the end is 13, padded to a multiple of 4 = 16.

More Programming and Data Structures (GATE) questions

Exams that ask this topic