ProgrammingModerateIBM · Deloitte pattern

With 32-bit unsigned int, what is printed?

With 32-bit unsigned int, what is printed?
unsigned int x = 0;
x--;
printf("%u %d", x, x > 0);
  1. A. 4294967295 1
  2. B. 4294967295 0
  3. C. 0 0
  4. D. -1 0

Correct answer: A. 4294967295 1

Unsigned arithmetic wraps modulo 2³², so 0 - 1 = 4294967295. That value is positive, so x > 0 is 1. Unsigned wraparound is defined, unlike signed overflow.

More C Programming questions

Exams that ask this topic