ProgrammingHardWipro · Cognizant pattern

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

Assume a 64-bit LP64 ABI. What is printed?
struct Point { int x; int y; };
struct Rect { struct Point tl; struct Point br; };
printf("%zu %zu", sizeof(struct Point), sizeof(struct Rect));
  1. A. 8 16
  2. B. 4 8
  3. C. 8 8
  4. D. 8 12

Correct answer: A. 8 16

Point has two 4-byte ints with no padding needed between them (both naturally aligned at offsets 0 and 4), so sizeof(Point)=8. Rect embeds two Points back-to-back (each already a clean multiple of int's alignment), so sizeof(Rect)=16 with no extra padding.

More C Programming questions

Exams that ask this topic