C Operator Precedence and
Associativity
Precedence Operators Description Associativity Unary/ Tips
Level Binary
1 (Highest) () [] . -> Function Left to Right Binary Always done
call, array first. () can
subscript, override all
member precedence
access
2 ++ -- Post- Left to Right Unary Use after
(postfix) increment, variable: a+
Post- +, a--
decrement
3 ++ -- + - ! ~ * Unary plus, Right to Left Unary Most
& sizeof minus, common in
logical not, expressions
bitwise not, like -a, !a,
dereference, *ptr
address, size
4 */% Multiply, Left to Right Binary Same as
divide, math rules.
modulo Do these
before + or -
5 +- Addition, Left to Right Binary Done after
subtraction multiplicatio
n
6 << >> Bitwise shift Left to Right Binary Use with
left/right integer bit
manipulatio
n
7 < <= > >= Relational Left to Right Binary Comparison
operators for size
8 == != Equality and Left to Right Binary Always done
inequality after
relational
ops
9 & Bitwise AND Left to Right Binary Not logical
AND! Works
on bits
10 ^ Bitwise XOR Left to Right Binary Toggle bits
11 | Bitwise OR Left to Right Binary Combine
bits
12 && Logical AND Left to Right Binary Both
conditions
must be true
13 || Logical OR Left to Right Binary At least one
must be true
14 ?: Ternary Right to Left Ternary cond ?
conditional true_val :
false_val
15 = += -= *= /= Assignment Right to Left Binary Right side
%= <<= >>= operators evaluated
&= ^= |= first
16 (Lowest) , Comma Left to Right Binary Evaluates
operator expressions
left to right