ProgrammingModerate

struct H { short s; char c; }; printf("%zu", sizeof(struct H)); What is printed with 2-byte short and natural alignment?

  1. A. 3
  2. B. 2
  3. C. 4
  4. D. 5

Correct answer: C. 4

s is at offset 0 with size 2, c is at offset 2, and the total is padded to the 2-byte alignment, giving 4 bytes.

More C Programming questions

Exams that ask this topic