ProgrammingHardTCS NQT · Infosys pattern

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

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

Correct answer: B. 12

a@0 (1 byte, then 3 padding bytes so b aligns to 4), b@4 (4 bytes), c@8 (1 byte), then 3 trailing padding bytes so the whole struct's size is a multiple of its strictest alignment (4, from int): total 12.

More C Programming questions

Exams that ask this topic