ProgrammingHardTCS NQT · Infosys

unsigned int n = 0u; int i = 0; if (i < n - 1) printf("loop"); What is printed?

  1. A. nothing
  2. B. loop
  3. C. -1
  4. D. undefined

Correct answer: B. loop

n - 1 wraps to UINT_MAX, and i is converted to unsigned for the comparison, so 0 < UINT_MAX is true. Unsigned counters like this are a classic bug in loops over sizes.

More C Programming questions

Exams that ask this topic