ProgrammingHardTCS NQT · Infosys

What is printed?

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

Correct answer: B. 0 1

In s < u, -2 converts to a huge unsigned value, so the comparison is false. The second comparison stays in int, where -2 + 1 = -1 is greater than -2.

More C Programming questions

Exams that ask this topic