ProgrammingHardTCS NQT · Infosys pattern

Assume 32-bit int. What is printed?

Assume 32-bit int. What is printed?
unsigned int a = 0;
a--;
printf("%u", a);
  1. A. -1
  2. B. 4294967295
  3. C. Undefined behaviour: decrementing below 0
  4. D. 0

Correct answer: B. 4294967295

Unsigned integer arithmetic in C is defined to wrap around modulo 2^(bit width), never undefined behaviour (unlike signed overflow). Decrementing 0 wraps to the maximum representable unsigned value, 2^32 - 1 = 4294967295.

More C Programming questions

Exams that ask this topic