C++优先级
程序员文章站
2022-06-27 22:59:06
C++ Operator Precedence
The following table lists the precedence(优先) and associativity(结合...
C++ Operator Precedence
The following table lists the precedence(优先) and associativity(结合性) of C++ operators. Operators are listed top to bottom, in descending(下降的) precedence.
Precedence | Operator | Description | Associativity |
---|---|---|---|
1 | :: |
Scope resolution | Left-to-right |
2 | a++ |
Suffix/postfix increment and decrement | |
type() |
Functional cast | ||
a() |
Function call | ||
a[] |
Subscript | ||
. |
Member access | ||
3 | ++a |
Prefix increment and decrement | Right-to-left |
+a |
Unary plus and minus | ||
! |
Logical NOT and bitwise NOT | ||
(type) |
C-style cast | ||
*a |
Indirection (dereference) | ||
&a |
Address-of | ||
sizeof |
Size-of[note 1] | ||
new |
Dynamic memory allocation | ||
delete |
Dynamic memory deallocation | ||
4 | .* |
Pointer-to-member | Left-to-right |
5 | a*b |
Multiplication(乘法), pision, and remainder | |
6 | a+b |
Addition and subtraction | |
7 | << |
Bitwise left shift and right shift | |
8 | < |
For relational operators < and ≤ respectively | |
> |
For relational operators > and ≥ respectively | ||
9 | == |
For relational operators = and ≠ respectively | |
10 | a&b |
Bitwise AND | |
11 | ^ |
Bitwise XOR (exclusive or) | |
12 | | |
Bitwise OR (inclusive or) | |
13 | && |
Logical AND | |
14 | || |
Logical OR | |
15 | a?b:c |
Ternary conditional[note 2] | Right-to-left |
throw |
throw operator | ||
= |
Direct assignment (provided by default for C++ classes) | ||
+= |
Compound assignment by sum and difference | ||
*= |
Compound assignment by product, quotient, and remainder | ||
<<= |
Compound assignment by bitwise(按位) left shift and right shift | ||
&= |
Compound assignment by bitwise AND, XOR, and OR | ||
16 | , |
Comma | Left-to-right |
上一篇: SPI接口下的OLED显示
下一篇: 想提升网站权重 你要做到保持内容原创更新