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 | |
equality | == != | 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 March 31, 2024 at 8:55PM
|
You can also obtain a PDF version of this. |