ProgrammingHardTCS NQT · Infosys pattern

Assume a 64-bit LP64 ABI with #pragma pack(1) applied to this struct only. What is printed?

Assume a 64-bit LP64 ABI with `#pragma pack(1)` applied to this struct only. What is printed?
#pragma pack(push, 1)
struct Packed {
    char a;
    int b;
    char c;
};
#pragma pack(pop)
printf("%zu", sizeof(struct Packed));
  1. A. 6
  2. B. 12
  3. C. 9
  4. D. 8

Correct answer: B. 12

pack(1) forces 1-byte alignment for every member, eliminating all padding: a@0 (1), b@1 (4, unaligned but packed), c@5 (1), total exactly 6 bytes with no trailing padding either.

More C Programming questions

Exams that ask this topic