Section 26.1 Operator Precedence
We first introduced operator precedence in Section 9.9. With the introduction of some new operators comes the necessity to discuss precedence of operators. In a command that involves multiple operations and operators, which get executed first? The direct and indirect member selection operators have high precedence as the following table shows. Operators at the top of the table have highest precedence (get executed before those that are below them in the table).
The entry in the “Order” column indicates how multiple operands are handled with respect to the given operation (remember, the computer can only do one thing at a time...). For example, when comparing two expressions using
<
, the expression to the left of the less than sign is evaluated before the one on the right. On the other hand, in an assignment statement such as a = b+1;
the right-hand side is evaluated first and only then assigned to the variable on the left.Operator | Precedence | Order |
(..) |
highest | left to right |
a[..] f(..) . ->
|
| | left to right |
i++ i--
|
| | right to left |
++i --i sizeof() ! + - & * (unary) |
| | right to left |
(int) (float) (casts) |
| | right to left |
/ %
|
| | left to right |
+ - (binary) |
| | left to right |
< <= >= >
|
| | left to right |
== !=
|
| | left to right |
&& |
| | left to right |
|| |
V | left to right |
= += -= *= /= %=
|
lowest | right to left |