ProgrammingVery hard

printf("%u", (0u - 1u) % 10); What is printed with 32-bit unsigned int?

  1. A. 9
  2. B. 4
  3. C. 0
  4. D. 5

Correct answer: D. 5

Unsigned arithmetic wraps modulo 2^32, so 0u - 1u = UINT_MAX = 4294967295, and its last digit gives % 10 = 5. 0 assumes unsigned subtraction stops at 0, and 9 guesses from a trailing 9 that the number does not have.

More C Programming questions

Exams that ask this topic