ProgrammingVery hardProduct company OA

Assume unsigned int bitfields pack into 32-bit allocation units and a zero-width bitfield forces the next field to a new unit. What is printed?

Assume unsigned int bitfields pack into 32-bit allocation units and a zero-width bitfield forces the next field to a new unit. What is printed?
struct ZW { unsigned a:3; unsigned :0; unsigned b:5; };
printf("%zu", sizeof(struct ZW));
  1. A. 4
  2. B. 1
  3. C. 5
  4. D. 8

Correct answer: D. 8

The unnamed :0 bitfield forces the next bitfield (b) to begin at the start of a new allocation unit, even though 29 bits were still free after a. So a occupies one 4-byte unit and b starts a second 4-byte unit: 8 bytes total.

More C Programming questions

Exams that ask this topic