This table, or one similar to it, can be found in almost every book on C. It’s worth keeping this with you as you program, because some of the precedences are not what you might expect.
precedence | class | operators | associativity |
highest | primary | () [] –> . | left to right |
unary | ~ ++ -- ! (type) sizeof & (address) * (pointer) + (positive sign) − (negative sign) | right to left | |
multiplicative | * / % | left to right | |
additive | + − | left to right | |
shift | << >> | left to right | |
relational | < <= => > | left to right | |
bitwise and | & | left to right | |
bitwise xor | ^ | left to right | |
bitwise or | | | left to right | |
logical and | && | left to right | |
logical or | || | left to right | |
conditional | ? : | right to left | |
assignment | = += −= *= /= %= &= ^= |= <<= =>> | right to left | |
lowest | comma | , | left to right |
|
ECS 36A, Programming and Problem Solving Version of September 20, 2019 at 7:40PM
|
You can also obtain a PDF version of this. |