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; }
4 Respostas
+ 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
0
I know the output it's 1211. I am unable to understand how it came.
0
Thanks shadow. It was helpful
0
me russian