运算符优先顺序(Order of Precedence of Operators)
以下是按evaluation顺序列出的运算符优先顺序。
优先级 | 描述 | 运算符 |
---|---|---|
1 | Postfix increment and decrement | ++, -- |
1 | New expression | new <typename> |
1 | Array subscripting | <array>[<index>] |
1 | Member access | <object>.<member> |
1 | Function-like call | <func>(<args...>) |
1 | Parentheses | (<statement>) |
2 | Prefix increment and decrement | ++, -- |
2 | Unary plus and minus | +, - |
2 | Unary operations | delete |
2 | Logical NOT | ! |
2 | Bitwise NOT | ~ |
3 | Exponentiation | ** |
4 | Multiplication, division and modulo | *, /, % |
5 | Addition and subtraction | +, - |
6 | Bitwise shift operators | <<, >> |
7 | Bitwise AND | & |
8 | Bitwise XOR | ^ |
9 | Bitwise OR | | |
10 | Inequality operators | <, >, <=, >= |
11 | Equality operators | ==, != |
12 | Logical AND | && |
13 | Logical OR | || |
14 | Ternary operator | <conditional> ? <if-true> : <if-false> |
15 | Assignment operators | =, |=, ^=, &=, <<=, >>=, +=, -=, *=, /=, %= |
16 | Comma operator | , |