[Solved] How does operator precedence affect order of evaluation?


Thus in a C++ program that is made up of value computations exclusively the evaluation order would entirely be dictated by operator precedence and associtivity. (2)

No, the evaluation order of value computations is not entirely dictated by operator precedence and associativity. They impose only a partial ordering on evaluation.

Consider a + b. In this, a and b must be evaluated before a + b, but either a or b may be evaluated first.

Also consider (a + b) * (c + d). Here, a + b and c + d must be evaluated before (a + b) * (c + d), but a, b, c, and d may be evaluated in any order. For example, a permissible order is b, d, c, c + d, a, a + b, (a + b) * (c + d).

In general, with most operators, operator precedence and associativity create a tree structure for the expression, and each node on the tree must be evaluated before its parent but does not have any ordering requirement with nodes on other branches. Some operators, such as && and || impose additional constraints, such as that the left operand must be fully evaluated before any part of the right operand is evaluated, if the right operand is evaluated. And some operators require that one operand not be evaluated, such as sizeof (except, in C [not yet in C++], when its operand is a variable length array) or the conditional operator (one of b or c in a ? b : c is not evaluated).

Regarding your other numbered paragraphs, I do not see any errors with them.

0

solved How does operator precedence affect order of evaluation?