ProgrammingVery hard

union U { int i; char c[6]; }; printf("%zu", sizeof(union U)); What is printed with 4-byte int and 1-byte char?

  1. A. 6
  2. B. 4
  3. C. 10
  4. D. 8

Correct answer: D. 8

A union is as large as its largest member, here c[6], and then rounded up to the 4-byte alignment of int, giving 8.

More C Programming questions

Exams that ask this topic