运算符优先顺序(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 | , |

本文详细介绍了编程语言中运算符的优先级顺序,从后缀运算符如递增递减到前缀运算符如逻辑非,再到乘除、加减等算术运算符,直至赋值运算符,为读者提供了清晰的运算符执行顺序指南。
2488

被折叠的 条评论
为什么被折叠?



