0

What is the output of this code and why?

int main() { int x=1,y=1,z=1; cout<<(++x||++y&&++z); cout<<x<<y<<z; }

13th Dec 2018, 9:05 PM
Mukul
Mukul - avatar
4 Antworten
+ 3
It's called Short Circuit Evaluation and is a common way of optimization used by many compilers. It means essentially the compiler will only evaluate what he needs to know in order to know the result of a statement. Some reference links: https://riptutorial.com/cplusplus/example/30129/logical----and----operators--short-circuit https://en.m.wikipedia.org/wiki/Short-circuit_evaluation https://softwareengineering.stackexchange.com/questions/325009/short-circuit-evaluation-is-c
13th Dec 2018, 9:17 PM
Shadow
Shadow - avatar
0
I know the output it's 1211. I am unable to understand how it came.
13th Dec 2018, 9:12 PM
Mukul
Mukul - avatar
0
Thanks shadow. It was helpful
13th Dec 2018, 9:22 PM
Mukul
Mukul - avatar
0
me russian
2nd Jan 2019, 10:27 PM
maksim harik