ProgrammingVery hardProduct company OA

On a typical x86-64 GCC/Clang target, what is printed?

On a typical x86-64 GCC/Clang target, what is printed?
struct F {
    unsigned a : 20;
    unsigned b : 20;
};
printf("%zu", sizeof(struct F));
  1. A. 4
  2. B. 8
  3. C. 5
  4. D. 10

Correct answer: B. 8

a:20 fills most of the first 32-bit allocation unit, leaving only 12 bits — not enough room for b:20, which (being the same declared type) must start a new unsigned-sized unit rather than straddle the boundary. Two 4-byte units are used: 8 bytes total.

More C Programming questions

Exams that ask this topic