原地址:http://www.cppreference.com/operator_precedence.html
C++ Operator Precedence
The operators at the top of this list are evaluated first.
Precedence | Operator | Description | Example | Associativity |
1 | :: | Scoping operator | Class::age = 2; | none |
2 | () | Grouping operator | (a + b) / 4; | left to right |
3 | ! | Logical negation | if( !done ) ... | right to left |
4 | ->* | Member pointer selector | ptr->*var = 24; | left to right |
5 | * | Multiplication | int i = 2 * 4; | left to right |
6 | + | Addition | int i = 2 + 3; | left to right |
7 | << | Bitwise shift left | int flags = 33 << 1; | left to right |
8 | < | Comparison less-than | if( i < 42 ) ... | left to right |
9 | == | Comparison equal-to | if( i == 42 ) ... | left to right |
10 | & | Bitwise AND | flags = flags & 42; | left to right |
11 | ^ | Bitwise exclusive OR | flags = flags ^ 42; | left to right |
12 | | | Bitwise inclusive (normal) OR | flags = flags | 42; | left to right |
13 | && | Logical AND | if( conditionA && conditionB ) ... | left to right |
14 | || | Logical OR | if( conditionA || conditionB ) ... | left to right |
15 | ? : | Ternary conditional (if-then-else) | int i = (a > b) ? a : b; | right to left |
16 | = | Assignment operator | int a = b; | right to left |
17 | , | Sequential evaluation operator | for( i = 0, j = 0; i < 10; i++, j++ ) ... | left to right |