When an expression has two operators with the same precedence, the expression is evaluated according to its associativity. I want to know how the following works:
i=b + b + ++b
i
here is 4
So ++b
didn't change the first 2 b
values, but it executed first, because the execution is from left to right.
Here, however:
int b=1;
i= b+ ++b + ++b ;
i
is 6
According to associativity, we should execute the 3rd b
so it should be:
1+ (++1) + ( ++1 should be done first)
. so it becomes:
1 + ++1 + 2 =5
However, this is not right, so how does this work?