ProgrammingVery hardTCS NQT · Infosys pattern

Assume a 64-bit LP64 ABI (4-byte int, 8-byte pointers, natural alignment). What is printed?

Assume a 64-bit LP64 ABI (4-byte int, 8-byte pointers, natural alignment). What is printed?
struct Inner { char a; short b; };
struct Outer { char x; struct Inner in; int y; };
printf("%zu %zu", sizeof(struct Inner), sizeof(struct Outer));
  1. A. 4 10
  2. B. 2 12
  3. C. 4 16
  4. D. 4 12

Correct answer: D. 4 12

Inner: a@0, pad 1, b@2, size 4 (align 2). Outer: x@0, pad 1 so in@2 (covers bytes 2-5), y needs 4-byte alignment so it moves to offset 8, ending at 12; struct alignment is 4, so no trailing padding is needed.

More C Programming questions

Exams that ask this topic