ProgrammingHardWipro · Cognizant pattern

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

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

Correct answer: B. 12

a@0 (4 bytes), b@4 (1 byte, then 3 padding bytes so c aligns to 4), c@8 (4 bytes). Total used is 12, which is already a multiple of 4, so no further trailing padding is needed: sizeof = 12.

More C Programming questions

Exams that ask this topic