C++ Operators and operator precedence

This page will be updated to reflect what you should know from this table. The operators that you have to know how to use have a white background. This page was last updated on 6/5/08.

Level  OperatorDescriptionAssociativity

0::scope resolutionLeft to Right

1++post-incrementLeft to Right
--post-decrement
()function call
[]array subscripting
.member selection via reference
->member selection via pointer
typeid()run-time type info
const_casttype cast
dynamic_casttype cast
reinterpret_casttype cast
static_casttype cast

2++pre-incrementRight to Left
--pre-decrement
+unary plus
-unary minus
!logical NOT
~bitwise NOT
(type)type cast
*dereference
&address-of
sizeofsize-of
newdynamic memory allocation
new[]dynamic array memory allocation
deletedynamic memory deallocation
delete[]dynamic array memory deallocation

3.*pointer to member using referenceLeft to Right
->*pointer to member using pointer

4*multiplicationLeft to Right
/division
%modulus (remainder)

5+additionLeft to Right
-subtraction

6<<bitwise left shiftLeft to Right
>>bitwise right shift

7<relational: less thanLeft to Right
<=relational: less than or equal
>relational: greater than
>=relational: greater than or equal

8==relational: equalLeft to Right
!=relational: not equal

9&bitwise ANDLeft to Right

10^bitwise XORLeft to Right

11|bitwise ORLeft to Right

12&&logical ANDLeft to Right

13||logical ORLeft to Right

14c?t:fconditional (ternary)Right to Left

15=assignmentRight to Left
+=addition and assignment
-=subtraction and assignment
*=multiplication and assignment
/=division and assignment
%=remainder and assignment
<<=bitwise left shift and assignment
>>=bitwise right shift and assignment
&=bitwise AND and assignment
^=bitwise XOR and assignment
|=bitwise OR and assignment

16throwthrow an exceptionN/A

17,list separatorLeft to Right

C++ also includes keywords as synonyms for some operators. They are as follows:

keyword     synonym for
and&&
and_eq&=
bitand&
bitor|
compl~
not!
not_eq!=
or||
or_eq|=
xor^
xor_eq^=