ProgrammingHardProduct company OA

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

Assume a 64-bit LP64 ABI. What is printed?
struct Variant {
    int type;
    union { int i; float f; double d; };
};
printf("%zu", sizeof(struct Variant));
  1. A. 12
  2. B. 16
  3. C. 8
  4. D. 24

Correct answer: B. 16

type@0 (4 bytes); the anonymous union's strictest member is double, so it needs 8-byte alignment and the union itself is 8 bytes, placed at offset 8 after 4 bytes of padding. Total size is 16.

More C Programming questions

Exams that ask this topic