ProgrammingHardTCS NQT · Infosys pattern

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

Assume a 64-bit LP64 ABI. What is printed?
struct Bitfields {
    unsigned a : 3;
    unsigned b : 5;
    unsigned c : 24;
};
printf("%zu", sizeof(struct Bitfields));
  1. A. 4
  2. B. 3
  3. C. 12
  4. D. 8

Correct answer: A. 4

a(3)+b(5)+c(24) = 32 bits total, which fits exactly into a single 4-byte unsigned int storage unit on typical implementations (bit-field packing is implementation-defined in detail, but GCC/Clang/MSVC on common ABIs all pack these into one 4-byte unit here), giving sizeof = 4.

More C Programming questions

Exams that ask this topic