ProgrammingHardGATE CS · TCS NQT

What is printed? Assume int is 32 bits.

What is printed? Assume int is 32 bits.
#include <stdio.h>
struct B { unsigned a : 3; };
int main(void) {
    struct B s;
    s.a = 13;
    printf("%d", s.a);
}
  1. A. 13
  2. B. 1
  3. C. 0
  4. D. 5

Correct answer: D. 5

Assigning 13 to a 3-bit unsigned field keeps the low three bits, 13 mod 8 = 5. The field cannot hold 13.

More C Programming questions

Exams that ask this topic