C++ 速查手冊
2.3 - 運算子
C++ 提供多樣、功能完整的運算子,依運算子結合後運算的優先次序 (precedence) ,如下列表
運算子 | 結合規則 | |
---|---|---|
1 | :: | 左到右 |
2 | () | 左到右 |
[] | ||
-> | ||
. | ||
++ | ||
-- | ||
dynamic_cast | ||
static_cast | ||
reinterpret_cast | ||
const_cast | ||
typeid | ||
3 | ! | 右到左 |
not | ||
~ | ||
compl | ||
++ | ||
-- | ||
- | ||
+ | ||
* | ||
& | ||
sizeof | ||
new | ||
new [] | ||
delete | ||
delete [] | ||
(type) | ||
4 | ->* | 左到右 |
.* | ||
5 | * | 左到右 |
/ | ||
% | ||
6 | + | 左到右 |
- | ||
7 | << | 左到右 |
>> | ||
8 | < | 左到右 |
<= | ||
> | ||
>= | ||
9 | == | 左到右 |
eq | ||
!= | ||
not_eq | ||
10 | & | 左到右 |
bitand | ||
11 | ^ | 左到右 |
xor | ||
12 | | | 左到右 |
bitor | ||
13 | && | 左到右 |
and | ||
14 | || | 左到右 |
or | ||
15 | ?: | 右到左 |
16 | = | 右到左 |
+= | ||
-= | ||
*= | ||
/= | ||
%= | ||
&= | ||
and_eq | ||
^= | ||
xor_eq | ||
|= | ||
or_eq | ||
<<= | ||
>>= | ||
17 | throw | |
18 | , | 左到右 |
包括算術運算子 (arithmetic operator) 、遞增 (increment) 及遞減運算子 (decrement operator) 、關係運算子 (relational operator) 、邏輯運算子 (logical operator) 、位元運算子 (bitwise operator) 、指派運算子 (assignment operator) 、條件運算子 (conditional operator) 等等。
相關教學影片