Precedence and 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
highestprimary  () [] –> . 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
lowestcomma ,left to right


UC Davis sigil
Matt Bishop
Office: 2209 Watershed Sciences
Phone: +1 (530) 752-8060
Email: mabishop@ucdavis.edu
ECS 36A, Programming and Problem Solving
Version of September 20, 2019 at 7:40PM

You can also obtain a PDF version of this.

Valid HTML 4.01 Transitional Built with BBEdit Built on a Macintosh