C Operator Precedence and Associativity Chart

©2001 by Wayne Pollock, Tampa Florida USA.  All Rights Reserved.

The C and C++ language includes many operators.  The operators with higher precedence are listed first.  Operators with equal precedence are shown in the same cell of the table.  Some explanatory notes are (shown in yellow italics).

When in doubt, use parenthesis!


Operator   Asociativity  
() (grouping) Left --> Right
() (function call)
[] (subscript)
->   . (member selector)
expr++   expr-- (postfix)

Left --> Right
Right --> Left
! ~ + - * & (unary)
++expr  --expr (prefix)
(type) (typecast or cast)
sizeof
Right --> Left
* / % (binary multiplicative) Left --> Right
+ - (binary additive) Left --> Right
<< >> (bitwise shift) Left --> Right
< <= > >= (relational) Left --> Right
== != (equality) Left --> Right
& (bitwise "and") Left --> Right
^ (bitwise "exclusive-or") Left --> Right
| (bitwise "or") Left --> Right
&& (logical "and") Left --> Right
|| (logical "or") Left --> Right
expr-1 ? expr-2 : expr-3 (conditional) Right --> Left
= *= /= %= += -= <<= >>= &= ^= |= (assignment) Right --> Left
, (comma operator) Left --> Right

This information was extracted from ISO 9899 (The C99 Standard), section 6.5.  Some of the operators listed there are omitted from this chart in the interest of clarity.  (For example, "(type-name){initializer-list}" is a C99 array literal listed in the standard as a postfix operator.  This so-called operator is not part of C89 and I believe most would not consider this or other literals and constants as operators, even if the C99 standard does.)  Some small differences (clarifications and new operators from C89) may be noted with your compiler, as few if any are fully C99 compliant at this time.




Send comments and mail to the WebMaster.