Precedence is the order in which the
compiler groups operands with operators. The C compiler evaluates
certain operators and their operands before others. If operands
are not grouped using parentheses, the compiler groups them according
to its own rules.
Table 5-1 “C Operator Precedence ” shows
the rules of operator precedence in the C language. The table lists
the highest precedence operators first. Most operators group from
the left to the right but some group from the right to the left.
The grouping indicates how an expression containing several operators
of the same precedence will be evaluated. Left to right grouping
means the expression
behaves as if it had been written:
Likewise, an operator that groups from the right to the left
causes the expression
to behave as if it had been written:
Table 5-1 C Operator Precedence
Operators | Grouping |
---|
() [] -> . | left to right |
+ ! ~
++ -- - *
& sizeof
(See note 1 below.) | right to left |
(type) | right to left |
* / % | left to right |
+ - | left to right |
<< >> | left to right |
< <= > >= | left to right |
== != | left to right |
& | left to right |
^ | left to right |
| | left to right |
&& | left to right |
|| | left to right |
?: | right to left |
= *= /= %= += -= <<= >>= &= ^= |= | right to left |
, | left to right |
1 Note that the +, -, *,
and &
operators listed in this row are unary operators.