ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
int a = -1;
unsigned int b = 1;
if (a < b) printf("less");
else printf("not less");
  1. A. Compilation error
  2. B. Undefined behaviour
  3. C. less
  4. D. not less

Correct answer: D. not less

In a comparison between int and unsigned int, the int is converted to unsigned: -1 becomes UINT_MAX (4294967295 for 32 bits), which is greater than 1. So it prints not less. Compilers warn about this signed/unsigned comparison.

More C Programming questions

Exams that ask this topic