ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
#include <stdio.h>
int main(void) {
    printf("%d", -1 < (unsigned)0);
}
  1. A. 1
  2. B. 0
  3. C. 2
  4. D. 3

Correct answer: B. 0

(unsigned)0 is 0 and -1 is converted to UINT_MAX, so -1 < 0 is false in this comparison. A signed comparison would print 1.

More C Programming questions

Exams that ask this topic