ProgrammingHardTCS NQT · Infosys pattern

Assume a 64-bit LP64 ABI. What is printed?

Assume a 64-bit LP64 ABI. What is printed?
union U {
    int i;
    char c[4];
    double d;
};
printf("%zu", sizeof(union U));
  1. A. 4
  2. B. 9
  3. C. 8
  4. D. 16

Correct answer: C. 8

A union's size is the size of its LARGEST member (double, 8 bytes), rounded up to satisfy that member's alignment (also 8), giving 8. Members are not summed like a struct; they all share the same starting address.

More C Programming questions

Exams that ask this topic