Your logic is close, but not entirely correct. Evaluation order from left to right for the + operator. t1 goes before the binary operator, LHS, and then the increment is on the RHS of this binary operand. LHS first.
t2 = t1 + (++t1); t2 = 5 + 6;
Visualized as the tree you have
+ / \ t1 ++t1
A priority
When two operators share an operand, the higher priority operator comes first. For example, 1 + 2 * 3 is considered as 1 + (2 * 3), while 1 * 2 + 3 is considered as (1 * 2) + 3, since multiplication has a higher priority than adding.
Associativity
When two operators are of the same priority, an expression is evaluated according to its associativity. For example, x = y = z = 17 is considered as x = (y = (z = 17)), leaving all three variables with a value of 17, since the = operator has left-handedness (and the assignment operator evaluates to the value on the right). On the other hand, 72/2/3 is considered as (72/2) / 3, since the operator / has left-right associativity.
Chris K Sep 10 '14 at 9:05 2014-09-10 09:05
source share