ProgrammingHardTCS NQT · Infosys pattern

What is printed?

What is printed?
union U { char c; int i; double d; };
printf("%zu", sizeof(union U));
  1. A. 13
  2. B. 8
  3. C. 4
  4. D. 16

Correct answer: B. 8

A union's size is the size of its largest member (double, 8 bytes) rounded up to the strictest alignment among members (also 8 for double), so sizeof(union U) is 8.

More C Programming questions

Exams that ask this topic