The following table lists the precedence and associativity of C + + operators. Operators is listed top to bottom, in descending precedence.
| Precedence |
Operator |
Description |
associativity |
| 1 |
:: |
Scope resolution |
Left-to-right |
| 2 |
++-- |
Suffix/postfix Increment and decrement |
type()type{} |
Function-style Type Cast |
() |
Function Call |
[] |
Array subscripting |
. |
Element Selection by reference |
-> |
Element selection through pointer |
| 3 |
++-- |
Prefix Increment and decrement |
Right-to-left |
+- |
Unary Plus and minus |
!~ |
Logical not and bitwise not |
(type) |
C-style Type Cast |
* |
indirection (dereference) |
& |
address-of |
sizeof |
size-of |
new,new[] |
Dynamic Memory allocation |
delete,delete[] |
Dynamic Memory deallocation |
| 4 |
.*->* |
Pointer to Member |
Left-to-right |
| 5 |
*/% |
Multiplication, division, and remainder |
| 6 |
+- |
Addition and subtraction |
| 7 |
<<>> |
Bitwise left shift and right shift |
| 8 |
<<= |
For relational operators < and≤respectively |
>>= |
For relational operators > and≥respectively |
| 9 |
==!= |
For relational = and≠respectively |
| 10 |
& |
Bitwise and |
| 11 |
^ |
Bitwise XOR (exclusive OR) |
| 12 |
| |
Bitwise or (inclusive or) |
| 13 |
&& |
Logical and |
| 14 |
|| |
Logical OR |
| 15 |
?: |
Ternary conditional |
Right-to-left |
= |
Direct assignment (provided by default for C + + classes) |
+=-= |
Assignment by Sum and difference |
*=/=%= |
Assignment by product, quotient, and remainder |
<<=>>= |
Assignment by bitwise left SHIFT and right shift |
&=^=|= |
Assignment by bitwise AND, XOR, and OR |
| 16 |
throw |
Throw operator (for exceptions) |
| 17 |
, |
Comma |
Left-to-right |
C + +-Operator precedence