### Question 3.4

Can I use explicit parentheses to force the order of evaluation I want? Even if I don't, doesn't precedence dictate it?

Not in general.

Operator precedence and explicit parentheses impose only a partial ordering on the evaluation of an expression. In the expression

    	f() + g() * h()

although we know that the multiplication will happen before the addition, there is no telling which of the three functions will be called first.

When you need to ensure the order of subexpression evaluation, you may need to use explicit temporary variables and separate statements.

References: K&R1 Sec. 2.12 p. 49, Sec. A.7 p. 185
K&R2 Sec. 2.12 pp. 52-3, Sec. A.7 p. 200

Read sequentially: prev next up top

This page by Steve Summit // Copyright 1995 // mail feedback