What will be the output of the following code? int main() {
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;
}
Show answerHide answer
Correct answer: (C) 1
Explanation
x > 0 is false, so the second conditional (y == 0) ? z : y is evaluated. y is 0, so the result is z = 1.