ProgrammingVery hardProduct company OA · GATE CS

What is printed?

What is printed?
int x = -1;
unsigned y = 1;
printf("%d", (x < 0 ? x : y) < 0);
  1. A. 0
  2. B. Undefined behaviour
  3. C. Compilation error
  4. D. 1

Correct answer: A. 0

The type of a ?: expression comes from both branches: int and unsigned int combine to unsigned int, whichever branch is chosen. The selected x is converted to UINT_MAX, which is not below 0.

More C Programming questions

Exams that ask this topic