The following table gives an overview of the precedence and associativity of operators.
| Operators | Associativity |
|---|---|
| () [] -> . | left to right |
| ! ~ ++ -- + - * & (type) sizeof | 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 |
The precedence and associativity is determined by the ANSI-C syntax (ANSI/ISO 9899-1990, p. 38 and Kernighan/ Ritchie, "The C Programming Language", Second Edition, Appendix Table 2-1).
if (a == b&&c) and if ((a == b)&&c) are equivalent. However, if (a == b|c) is the same as if ((a == b)|c) a = b + c * d;
In above listing, operator-precedence causes the product of (c*d) to be added to b, and that sum is then assigned to a.
In the following listing, the associativity rules first evaluates c+=1, then assigns b to the value of b plus (c+=1), and then assigns the result to a.
a = b += c += 1;