ProgrammingHardProduct-company MCQ pattern

Assume a 64-bit LP64 ABI (natural alignment, no #pragma pack). What is printed?

Assume a 64-bit LP64 ABI (natural alignment, no #pragma pack). What is printed?
struct A { char c; int i; char d; };
struct B { int i; char c; char d; };
printf("%zu %zu", sizeof(struct A), sizeof(struct B));
  1. A. 6 6
  2. B. 12 8
  3. C. 8 12
  4. D. 12 6

Correct answer: C. 8 12

A: c@0 (1 byte), padding to 4, i@4 (4 bytes), d@8 (1 byte), then the struct is padded to a multiple of its strictest alignment (4), giving 12. B: i@0 (4 bytes), c@4, d@5, total 6 bytes used, already a multiple of 4, so no trailing pad needed: 8 bytes total. Output: 12 8.

More C Programming questions

Exams that ask this topic