+ 1
C - Why is output 0?
int x = 1?0:2?3:4; printf("%d",x);
5 Antworten
+ 4
Because the first conditional is true then it does not evaluate the second conditional.
+ 2
It's conditional statement so that if the condition is true then it stops and won't execute the remaining code.So the output is 0 not 4
+ 1
Paolo De Nictolis any conditional operator, and, or operator which decide the code execution by evaluation of any part true or false have an property or follow an property which is known as "Short Circuit behavior" this behavior occurs when any part RHS or LHS evaluated to true it won't check for remaining part
Conditional expressions group right-to-left. The first expression is contextually converted to bool . It is evaluated and if it is true, and if that part is true other part evaluation is halted
have an read here at wiki page
https://en.m.wikipedia.org/wiki/Short-circuit_evaluation
and enjoy 🍎 🍎
0
Conditional ? True : False;
1 ? = True => x = 0
0
I understand. But why second conditional isn't executed, so that x "remains" 0, instead of being 4?