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
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
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 March 31, 2024 at 8:55PM

You can also obtain a PDF version of this.

Valid HTML 4.01 Transitional Built with BBEdit Built on a Macintosh