What does this statement mean? Also tell it's output | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What does this statement mean? Also tell it's output

Int exp = 1?0:2?3:4 ; Printf("%d",exp);

3rd Sep 2019, 5:31 PM
Om Jain
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.
3rd Sep 2019, 5:50 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 3
0
4th Sep 2019, 2:15 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 1
So what is output?
4th Sep 2019, 12:16 PM
Om Jain