ProgrammingHardWipro · Cognizant pattern

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

Assume a 64-bit LP64 ABI. What is printed?
struct Vec3 { double x, y, z; };
struct Mesh { struct Vec3 *verts; int count; };
printf("%zu %zu", sizeof(struct Vec3), sizeof(struct Mesh));
  1. A. 24 12
  2. B. 24 16
  3. C. 24 20
  4. D. 20 16

Correct answer: B. 24 16

Vec3 is three doubles, no padding needed: 24 bytes. Mesh: verts (pointer, 8 bytes)@0, count (int, 4 bytes)@8, end 12, padded up to 16 because the struct's alignment is 8 (driven by the pointer member).

More C Programming questions

Exams that ask this topic