ProgrammingHardWipro · Cognizant pattern

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

Assume a 64-bit LP64 ABI. What is printed?
union Shape {
    struct { double radius; } circle;
    struct { double width, height; } rect;
};
printf("%zu", sizeof(union Shape));
  1. A. 8
  2. B. 16
  3. C. 24
  4. D. 4

Correct answer: B. 16

The union's size is the size of its largest member: the anonymous rect struct, which is two doubles (width, height) with no padding needed = 16 bytes; circle is only 8 bytes, so the union is sized to fit the larger member: 16.

More C Programming questions

Exams that ask this topic