Next: Exercises Up: Basic C Programming Previous: Logical Operators

Order of Precedence

It is necessary to be careful of the meaning of such expressions as a + b * c

We may want the effect as either

(a + b) c

or

a + (b c)

All operators have a priority, and high priority operators are evaluated before lower priority ones. Operators of the same priority are evaluated from left to right, so that

a - b - c

is evaluated as

( a - b ) - c

as you would expect.

From high priority to low priority the order for all C operators (we have not met all of them yet) is:

Thus

a < 10 &&2 b < c

is interpreted as

( a < 10 ) &&( ( 2 b ) < c )

and

as


Dave.Marshall@cm.cf.ac.uk
Wed Sep 14 10:06:31 BST 1994