优先级 | 操作符 | 描述 | 例子 | 结合性 |
1 | () | 调节优先级的括号操作符 | (a + b) / 4; | 从左到右 |
2 | ! | 逻辑取反操作符 | if( !done ) ... | 从右到左 |
3 | ->* | 在指针上通过指向成员的指针访问成员的操作符 | ptr->*var = 24; | 从左到右 |
4 | * | 乘法操作符 | int i = 2 * 4; | 从左到右 |
5 | + | 加法操作符 | int i = 2 + 3; | 从左到右 |
6 | << | 按位左移操作符 | int flags = 33 << 1; | 从左到右 |
7 | < | 小于比较操作符 | if( i < 42 ) ... | 从左到右 |
8 | == | 等于比较操作符 | if( i == 42 ) ... | 从左到右 |
9 | & | 按位与操作符 | flags = flags & 42; | 从左到右 |
10 | ^ | 按位异或操作符 | flags = flags ^ 42; | 从左到右 |
11 | | | 按位或操作符 | flags = flags | 42; | 从左到右 |
12 | && | 逻辑与操作符 | if( conditionA && conditionB ) ... | 从左到右 |
13 | || | 逻辑或操作符 | if( conditionA || conditionB ) ... | 从左到右 |
14 | ? : | 三元条件操作符 | int i = (a > b) ? a : b; | 从右到左 |
15 | = | 赋值操作符 | int a = b; | 从右到左 |
16 | , | 逗号操作符 | for( i = 0, j = 0; i < 10; i++, j++ ) ... | 从左到右 |
Precedence | Operator | Description | Example | Associativity |
1 | () | Grouping operator | (a + b) / 4; | left to right |
2 | ! | Logical negation | if( !done ) ... | right to left |
3 | ->* | Member pointer selector | ptr->*var = 24; | left to right |
4 | * | Multiplication | int i = 2 * 4; | left to right |
5 | + | Addition | int i = 2 + 3; | left to right |
6 | << | Bitwise shift left | int flags = 33 << 1; | left to right |
7 | < | Comparison less-than | if( i < 42 ) ... | left to right |
8 | == | Comparison equal-to | if( i == 42 ) ... | left to right |
9 | & | Bitwise AND | flags = flags & 42; | left to right |
10 | ^ | Bitwise exclusive OR | flags = flags ^ 42; | left to right |
11 | | | Bitwise inclusive (normal) OR | flags = flags | 42; | left to right |
12 | && | Logical AND | if( conditionA && conditionB ) ... | left to right |
13 | || | Logical OR | if( conditionA || conditionB ) ... | left to right |
14 | ? : | Ternary conditional (if-then-else) | int i = (a > b) ? a : b; | right to left |
15 | = | Assignment operator | int a = b; | right to left |
16 | , | Sequential evaluation operator | for( i = 0, j = 0; i < 10; i++, j++ ) ... | left to right |