ProgrammingVery hardIBM · Deloitte pattern

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

Assume a 64-bit LP64 ABI. What is printed?
struct Inner { char c; int i; };
struct Outer { int x; struct Inner in; double d; };
printf("%zu %zu %zu", sizeof(struct Inner), offsetof(struct Outer, in), sizeof(struct Outer));
  1. A. 8 8 24
  2. B. 8 4 16
  3. C. 9 4 24
  4. D. 8 4 24

Correct answer: D. 8 4 24

Inner: c@0, i@4 (padded), end 8 (align 4) -> size 8. Outer: x@0 (4 bytes), in's own alignment is 4 so it can start right at offset 4 (no gap), occupying 4-11; d needs align 8, so it's placed at offset 16 (padding 12-15); end 24, already a multiple of 8.

More C Programming questions

Exams that ask this topic