Associativity of C Operators

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 exclusive or ^ 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 30-A, Introduction to Programming
Winter Quarter 2002
Email: cs30a@cs.ucdavis.edu