Priority does not affect the evaluation order (except when necessary - some subexpressions may be evaluated before others due to priority). For example, in simple terms:
a() + b() + c() * d()
although multiplication takes precedence over addition, the compiler can make function calls in any order that it likes, and it can call a() or b() before or after the multiplication. Obviously, he must evaluate c() and d() before he performs the multiplication. If these functions have side effects (for example, changing and using global variables), an uncertain evaluation order can lead to unexpected results.
However, for some operators, the standard defines a strict evaluation procedure. This can be said about the logic or operator || :
Unlike bitwise | operator, || the operator guarantees an assessment from left to right; There is a sequence point after evaluating the first operand. If the first operand compares not equal to 0, the second operand is not evaluated.
Thus, not only || provides an order guarantee, but also guarantees that under certain conditions the second operand will not be evaluated at all.
(he also says something similar for && - except that in this case the second operand is not evaluated if the first evaluates to 0. But in your example, || appears first).
Other operators that provide some sort of guarantee of order include a comma operator and a function call (which ensures that the arguments are evaluated, but not the order in which these arguments are evaluated).
Michael burr
source share