A table follows listing the operators, in descending order of precedence with the kind of operation. When several operators appear in the same line of the table, they have the same precedence.
Higher precedence operators are always evaluated first in an expression.
Operator Symbol | Kind of Operation |
---|---|
() [ ] . -> | primary highest precedence |
- +
~
!
* &
++ -- sizeof() (cast) |
unary |
* / % | multiplicative |
+ - | additive |
<< >> | shift |
< > <= >= | relational (inequality) |
== != | relational (equality) |
& | bitwise AND |
^ | bitwise XOR |
| | bitwise OR |
&& | logical AND |
|| | logical OR |
? : | conditional |
= *= /= %= += -= <= >>= &= ^= |= | assignment |
, | sequential evaluation lowest precedence |
Note that parenthesis have the same precedence whether they are used to delimit the expressions for parameters passed to a function, or they are used to reorder the evaluation of sub-expressions.
Using the operator precedence chart above, the following expression:
*[x+5*z]+a%z<<3
would be evaluated in the order (shown by parenthesis and a parse tree below - '.' for operators, '\|/' for operands):
(((*([(x+(5*z))])+(a%z))<<3) . . |. \./ . . \./ . | . . | . * . . % . / . . \./ . . / . / . . + . . / . / . .|. . / . / . [] . / . / .| . / . / * . | . / \ . / . / + . / \ . / << |