0
What does this statement mean? Also tell it's output
Int exp = 1?0:2?3:4 ; Printf("%d",exp);
3 Answers
+ 6
It is nested ternary, syntax for ternary operator is:
condition? true-case : false-case;
In this case exp will be equal to 0.
1? 0 : 2? 3 : 4;
As in the condition part, the constant value is 1 which evaluates to true so the true case will be executed which has a constant value 0.
Edit:
Nested ternary is similar to nested if-else-if.
+ 3
0
+ 1
So what is output?