ProgrammingVery hardTCS NQT · Infosys

For unsigned int i = 3; i >= 0; i--, what happens to the loop body?

  1. A. It runs 4 times
  2. B. It loops forever
  3. C. It is a compile error
  4. D. It is undefined behaviour

Correct answer: B. It loops forever

An unsigned value is never negative, so i >= 0 is always true. When i wraps from 0 to UINT_MAX the loop goes on, so it never ends. The wrap itself is well defined.

More C Programming questions

Exams that ask this topic