ProgrammingVery hardWipro · Cognizant pattern

Assume unsigned int bitfields pack into 32-bit units and a 64-bit LP64 ABI. What is printed?

Assume unsigned int bitfields pack into 32-bit units and a 64-bit LP64 ABI. What is printed?
#include <stddef.h>
struct M { unsigned a:10; unsigned b:10; char c; };
printf("%zu %zu", offsetof(struct M, c), sizeof(struct M));
  1. A. 4 5
  2. B. 4 8
  3. C. 0 8
  4. D. 4 12

Correct answer: B. 4 8

a and b together use 20 of the 32 bits in one allocation unit, which still occupies the full 4 bytes. c, needing only 1-byte alignment, is placed right after at offset 4. The struct's alignment is governed by unsigned (4), so the 5-byte logical size is padded up to 8.

More C Programming questions

Exams that ask this topic