C++ Operator Precedence and Associativity

 

This page lists all C++ operators in order of their precedence (highest to lowest).

Their associativity indicates in what order operators of equal precedence in an expression are applied.

 

Operator

Description

Associativity

::

Binary/unary scope resolution

l-to-r

( )
[ ]
.
->
++
--
typeid
dynamic_cast<type>
static_cast<type>
reinterpret_cast<type>
const_cast<type>

Parentheses (grouping)
Brackets (array subscript)
Member selection via object name
Member selection via pointer
Unary postincrement
Unary postdecrement
Run-time type information
Run-time type-checked cast
Compile-time type-checked cast
Cast for non-standard conversions
Cast away const-ness

l-to-r

++  --
+  -
!  ~
( type )
sizeof
&
*
new
new [ ]
delete
delete [ ]  

Unary preincrement/predecrement
Unary plus/minus
Unary logical negation/complement
Unary cast (change type)
Determine size in bytes
Address
Dereference
Dynamic memory allocation
Dynamic array allocation
Dynamic memory deallocation
Dynamic array deallocation

r-to-l

.*
->*

Pointer to member via object
Pointer to member via pointer

l-to-r

*    /    %

Multiplication/division/modulus

l-to-r

+  -

Addition/subtraction

l-to-r

<<   >>

Bitwise shift left/right

l-to-r

<   <=
>   >=

Relational less than/or equal to
Relational greater than/or equal to

l-to-r

==   !=

Relational is/is not equal to

l-to-r

&

Bitwise AND

l-to-r

^

Bitwise exclusive OR

l-to-r

|

Bitwise inclusive OR

l-to-r

&&

Logical AND

l-to-r

||

Logical OR

l-to-r

?:

Ternary conditional

r-to-l

=
+=   -=
*=   /=
%=   &=
^=   |=
<<=  >>=

Assignment
Addition/subtraction assignment
Multiplication/division assignment
Modulus/bitwise AND assignment
Bitwise exclusive/inclusive OR
Bitwise shift left/right assignment

r-to-l

,

Comma (separate expressions)

l-to-r