Question discussion

What will be the output of the following code?

359231Medium DSSSB TGT Computer Science 0 replies 0 views
0
What will be the output of the following code?
#include <stdio.h>
int main() {
    int x = -1, y = 0, z = 1;
    int result = (x > 0) ? x : (y == 0) ? z : y;
    printf("%d", result);
    return 0;
}
  • Acompile time error
  • B−1
  • C1
  • D0
Correct answer: C

Explanation

x > 0 is false, so the second conditional is evaluated: y == 0 is true, so the result is z = 1.

Discussion 0

Nobody has replied yet. Start the discussion!