ProgrammingVery hardHCL · Tech Mahindra pattern

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

Assume a 64-bit LP64 ABI. What is printed?
struct A { char a; double d; char b; };
struct B { double d; char a; char b; };
printf("%zu %zu", sizeof(struct A), sizeof(struct B));
  1. A. 16 16
  2. B. 24 24
  3. C. 16 24
  4. D. 24 16

Correct answer: D. 24 16

A: a@0, pad 7 so d@8 (8 bytes, ending at 16), b@16, then pad 7 to round to the double's 8-byte alignment: 24. B: d@0 (8 bytes), a@8, b@9, then pad 6 to reach 16 (next multiple of 8). Reordering the fields shrinks B by 8 bytes.

More C Programming questions

Exams that ask this topic