C/C++ Operator Precedence

This page presents a table of the operators available in C++, their order of precedence, and the order of their associativity.
OperatorDescription Usage and Notes

Scope operators (Left to right)

C++:: scope resolution class_name :: member
C++:: global :: name

. member selction object . member
-> member selection pointer -> member
[] subscripting pointer[expr]
() function call expr(expr_list)
C++() constructor type(expr_list)
sizeof size of object sizeof expr
sizeof size of type sizeof(type)

Unary operators (Right to left)

++ post increment lvalue ++
++ pre increment ++ lvalue
-- post decrement lvalue --
-- pre decrement -- lvalue
~ bitwise complement ~ expr
! logical not ! expr
Any non-zero value is logically true
- unary minus - expr
+ unary plus + expr
& address of & lvalue
* dereference * expr
C++new create (allocate) new type
C++delete destroy (de-allocate) delete pointer
C++delete [] destroy array delete [] pointer
() cast (type) expr

Member selection operators (Left to right)

C++.* member selection object .* pointer to member
C++->* member selection pointer ->* pointer to member

Arithmetic operators (Left to right)

* multiply expr * expr
/ divide expr / expr
% modulo expr % expr

+ add expr + expr
- subtract expr - expr

<< shift left expr << expr
>> shift right expr >> expr

Relational operators (Left to right)

< <= > >= conditionals True/false values are non-zero/zero, not always 1/0

== != equality

Bitwise operators (Left to right)

& bitwise AND

^ bitwise XOR

| bitwise OR

Logical operators (Left to right)

&& logical AND

|| logical OR

? : ternary operator expr ? expr : expr

Assignment operators (Right to left)

= *= /= %= assignment operators lvalue assignment expr
+= -= <<= >>=
&= |= ^=

Exception operator (Left to right)

C++throw throw exception throw expr

Sequence operator (Left to right)

, sequencing expr, expr