I am trying to run this simple code
int a=0;
cout<<a<<a++;
but the output is not what I expected
10
I would expect "00" and a=1, why is the answer different?
I am trying to run this simple code
int a=0;
cout<<a<<a++;
but the output is not what I expected
10
I would expect "00" and a=1, why is the answer different?
And what do you expect? Or more correctly, you're wrong to expect anything: you're modifying a variable, and accessing it for reasons other than determining the value to write, with no intervening sequence point, so the code has undefined behavior. It might output "10", it might output "01", or it might output "42", or even crash.
The C++ standard does not specify an order of execution for subexpressions
Except where noted, the order of evaluation of operands of individual operators and subexpressions of individual expressions, and the order in which side effects take place, is unspecified...
It is simple... As per my knowledge in C++ order of execution of any statement starts from right... in cout<