ProgrammingHard

struct G { int x; char y[3]; }; printf("%zu", sizeof(struct G)); What is printed with 4-byte int and natural alignment?

  1. A. 7
  2. B. 8
  3. C. 9
  4. D. 12

Correct answer: B. 8

x takes offsets 0 to 3, y takes offsets 4 to 6, and the struct is padded to the 4-byte alignment, giving 8.

More C Programming questions

Exams that ask this topic