The question is absurdly long for what it's trying to ask. I tried (without submitting) to cut out noise (keep in mind that this is not a discussion forum) and redundancy, and I still found that there was a multiple-paragraph exposition of a mental model, just to get to an actual question of "is this mental model correct?"
The thing is, the concept isn't remotely that complicated.
The question title already succinctly states the underlying question: "How does Operator Precedence affect Order of evaluation?" As asked, this is fairly vacuous. In the example code int i=++a*b+c/d/e
, the steps are - as you've already identified:
++a
is evaluated, incrementing a
and using the new value.
a * b
and c / d / e
are evaluated (each is a term in the arithmetic expression), in an undefined order.
- The two terms are added.
- The result is assigned to
i
.
"Operator precedence" is the name of the rule that tells you that a * b
and c / d / e
have to be evaluated before the +
, rather than (if +
had the same precedence as *
and /
) evaluating everything left to right or (if the precedence relationship were inverted) evaluating b + c
before all of the multiplications and divisions.
It has nothing to do with optimizations. Optimization might become possible due to the fact that the compiler can choose whether to compute a * b
or c / d / e
first. But both "operator precedence" and "order of operation" are about what things do have to happen before whichever other things. It's because the compiler is allowed to ignore side effects when choosing an order for those two steps, that undefined behaviour occurs. (That is the importance of sequence points.)
I guess I accidentally answered the entire question - as far as I could make any sense out of it - rather than figuring out how to make a proper question out of it. It was a lot easier that way. Oops.