ProgrammingVery hard

With int a = -1 and unsigned int b = 0, what does the expression a < b evaluate to?

  1. A. 0 (false), because a is converted to unsigned and becomes a huge value
  2. B. 1 (true), because -1 is less than 0
  3. C. It is undefined behaviour
  4. D. A compile error in C

Correct answer: A. 0 (false), because a is converted to unsigned and becomes a huge value

The usual arithmetic conversions turn -1 into 4294967295, which is not less than 0. The result is well defined and surprising.

More C Programming questions

Exams that ask this topic