Precedence Level | Symbol | Description | Associativity |
1 | :: | C++ scope access/resolution | Left to right |
2 | () | Function call | Left to right |
[] | Array subscript | ||
-> | Visual C++ indirect component selector | ||
. | C++ direct component selector | ||
3 | |||
Unary | ! | Logical negation | Right to left |
~ | Bitwise (1's) complement | ||
+ | Unary plus | ||
- | Unary minus | ||
& | Address of | ||
* | Indirection | ||
sizeof | Returns size of operand in bytes | ||
new | Dynamically allocates C++ storage | ||
delete | Dynamically deallocates C++ storage | ||
type | Typecast | ||
4 | |||
Member Access | .* | C++ dereference | Left to right |
->* | C++ dereference | ||
() | Expression parentheses | ||
5 | |||
Multiplicative | * | Multiply | Left to right |
/ | Divide | ||
% | Remainder (modulus) | ||
6 | |||
Additive | + | Binary plus | Left to right |
- | Binary minus | ||
7 | |||
Shift | << | Leftshift | Left to right |
>> | Rightshift | ||
8 | |||
Relational | < | Less than | Left to right |
<= | Less than or equal to | ||
> | Greater than | ||
>= | Greater than or equal to | ||
9 | |||
Equality | == | Equal to | Left to right |
!= | Not equal to | ||
10 | & | Bitwise AND | Left to right |
11 | ^ | Bitwise XOR | Left to right |
12 | | | Bitwise OR | Left to right |
13 | && | Logical AND | Left to right |
14 | || | Logical OR | Left to right |
15 | |||
Ternary | ?: | Conditional | Right to left |
16 | |||
Assignment | = | Simple assignment | Right to left |
*= | Compound assign product | ||
/= | Compound assign quotient | ||
%= | Compound assign remainder | ||
+= | Compound assign sum | ||
-= | Compound assign difference | ||
&= | Compound assign bitwise AND | ||
^= | Compound assign bitwise XOR | ||
|= | Compound assign bitwise OR | ||
<<= | Compound assign left shift | ||
>>= | Compound assign right shift | ||
17 | |||
Comma | , | Sequence point | Left to right |
Because of the confusion in most precedence tables, the postfix ++ and -- and the prefix ++ and -- don't appear here. The postfix operators usually appear in level 2, and the prefix operators appear in level 3. In practice, perform prefix before all other operators except for the scope resolution operator, and perform postfix right before the statement continues to the next executable statement in the program. Visual C++ purists will cringe at this description, but it works 99.9 percent of the time, while the "technically correct" placements of these operators simply confuse programmers 99.9 percent of the time.