ProgrammingModerateProduct-company MCQ pattern

What is printed?

What is printed?
if (-1 < 1u) printf("yes");
else printf("no");
  1. A. yes
  2. B. compile error
  3. C. undefined
  4. D. no

Correct answer: D. no

When int meets unsigned int, the int is converted to unsigned: −1 becomes UINT_MAX (4294967295 with 32-bit int), which is not less than 1. Mixing signed and unsigned in comparisons is a classic source of bugs (compilers warn with -Wsign-compare).

More C Programming questions

Exams that ask this topic