首頁(yè)/
站長(zhǎng)工具/
{notempty name="current_name"}
運(yùn)算符優(yōu)先級(jí)對(duì)照表
{notempty name="$current_name"}

運(yùn)算符優(yōu)先級(jí)對(duì)照表
【權(quán)威指南】Java、Python、C++、C#、PHP等主流編程語(yǔ)言運(yùn)算符優(yōu)先級(jí)對(duì)照表,提供跨語(yǔ)言對(duì)比與詳細(xì)解析??焖僬莆者\(yùn)算符執(zhí)行順序規(guī)則,避免代碼邏輯錯(cuò)誤,提升開(kāi)發(fā)效率。包含算術(shù)/邏輯/位運(yùn)算符優(yōu)先級(jí)詳解及常見(jiàn)誤區(qū)解析。
- Java運(yùn)算符
- C++運(yùn)算符
- C語(yǔ)言運(yùn)算符
- PHP運(yùn)算符
- Python運(yùn)算符
運(yùn)算符 | 優(yōu)先級(jí) |
---|---|
postfix | expr++ expr-- |
unary | ++expr --expr +expr -expr ~ ! |
multiplicative | * / % |
additive | + - |
shift | << >> >>> |
relational | < > <= >= instanceof |
equality | == != |
bitwise AND | & |
bitwise exclusive OR | ^ |
bitwise inclusive OR | | |
logical AND | && |
logical OR | || |
ternary | ? : |
assignment | = += -= *= /= %= &= ^= |= <<= >>= >>>= |
Precedence | Operator | Description | Associativity |
---|---|---|---|
1 | :: |
Scope resolution | Left-to-right |
2 |
++ --
|
Suffix/postfix increment and decrement | |
()
|
Function call | ||
[]
|
Array subscripting | ||
.
|
Element selection by reference | ||
->
|
Element selection through pointer | ||
3 |
++ --
|
Prefix increment and decrement | Right-to-left |
+ -
|
Unary plus and minus | ||
! ~
|
Logical NOT and bitwise NOT | ||
(type)
|
Type cast | ||
*
|
Indirection (dereference) | ||
&
|
Address-of | ||
sizeof
|
Size-of | ||
new , new[]
|
Dynamic memory allocation | ||
delete , delete[]
|
Dynamic memory deallocation | ||
4 |
.* ->*
|
Pointer to member | Left-to-right |
5 |
* / %
|
Multiplication, division, and remainder | |
6 |
+ -
|
Addition and subtraction | |
7 |
<< >>
|
Bitwise left shift and right shift | |
8 |
< <=
|
For relational operators < and ≤ respectively | |
> >=
|
For relational operators > and ≥ respectively | ||
9 |
== !=
|
For relational = and ≠ respectively | |
10 |
&
|
Bitwise AND | |
11 |
^
|
Bitwise XOR (exclusive or) | |
12 |
|
|
Bitwise OR (inclusive or) | |
13 |
&&
|
Logical AND | |
14 |
||
|
Logical OR | |
15 |
?:
|
Ternary conditional | Right-to-Left |
16 |
=
|
Direct assignment (provided by default for C++ classes) | |
+= -=
|
Assignment by sum and difference | ||
*= /= %=
|
Assignment by product, quotient, and remainder | ||
<<= >>=
|
Assignment by bitwise left shift and right shift | ||
&= ^= |=
|
Assignment by bitwise AND, XOR, and OR | ||
17 |
throw
|
Throw operator (for exceptions) | |
18 |
,
|
Comma | Left-to-right |
Precedence | Operator | Description | Associativity |
---|---|---|---|
1 |
++ --
|
Suffix/postfix increment and decrement | Left-to-right |
()
|
Function call | ||
[]
|
Array subscripting | ||
.
|
Structure and union member access | ||
->
|
Structure and union member access through pointer | ||
(type){list}
|
Compound literal(C99) | ||
2 |
++ --
|
Prefix increment and decrement | Right-to-left |
+ -
|
Unary plus and minus | ||
! ~
|
Logical NOT and bitwise NOT | ||
(type)
|
Type cast | ||
*
|
Indirection (dereference) | ||
&
|
Address-of | ||
sizeof
|
Size-of | ||
_Alignof
|
Alignment requirement(C11) | ||
3 |
* / %
|
Multiplication, division, and remainder | Left-to-right |
4 |
+ -
|
Addition and subtraction | |
5 |
<< >>
|
Bitwise left shift and right shift | |
6 |
< <=
|
For relational operators < and ≤ respectively | |
> >=
|
For relational operators > and ≥ respectively | ||
7 |
== !=
|
For relational = and ≠ respectively | |
8 |
&
|
Bitwise AND | |
9 |
^
|
Bitwise XOR (exclusive or) | |
10 |
|
|
Bitwise OR (inclusive or) | |
11 |
&&
|
Logical AND | |
12 |
||
|
Logical OR | |
13 |
?:
|
Ternary conditional | Right-to-Left |
14 |
=
|
Simple assignment | |
+= -=
|
Assignment by sum and difference | ||
*= /= %=
|
Assignment by product, quotient, and remainder | ||
<<= >>=
|
Assignment by bitwise left shift and right shift | ||
&= ^= |=
|
Assignment by bitwise AND, XOR, and OR | ||
15 |
,
|
Comma | Left-to-right |
結(jié)合方向 | 運(yùn)算符 | 附加信息 |
---|---|---|
非結(jié)合 | clone new |
clone 和 new |
左 | [ |
array() |
非結(jié)合 | ++ -- |
遞增/遞減運(yùn)算符 |
非結(jié)合 | ~ - (int) (float) (string) (array) (object) (bool) @ |
類(lèi)型 |
非結(jié)合 | instanceof |
類(lèi)型 |
右結(jié)合 | ! |
邏輯操作符 |
左 | * / % |
算術(shù)運(yùn)算符 |
左 | + - . |
算術(shù)運(yùn)算符 和 字符串運(yùn)算符 |
左 | << >> |
位運(yùn)算符 |
非結(jié)合 | < <= > >= <> |
比較運(yùn)算符 |
非結(jié)合 | == != === !== |
比較運(yùn)算符 |
左 | & |
位運(yùn)算符 和 引用 |
左 | ^ |
位運(yùn)算符 |
左 | | |
位運(yùn)算符 |
左 | && |
邏輯運(yùn)算符 |
左 | || |
邏輯運(yùn)算符 |
左 | ? : |
三元運(yùn)算符 |
右 |
= += -= *= /= .= %= &= |= ^= <<= >>=
|
賦值運(yùn)算符 |
左 | and |
邏輯運(yùn)算符 |
左 | xor |
邏輯運(yùn)算符 |
左 | or |
邏輯運(yùn)算符 |
左 | , |
多處用到 |
運(yùn)算符 | 描述 |
---|---|
lambda |
Lambda表達(dá)式 |
or |
布爾“或” |
and |
布爾“與” |
not x |
布爾“非” |
in,not in |
成員測(cè)試 |
is,is not |
同一性測(cè)試 |
<,<=,>,>=,!=,== |
比較 |
| |
按位或 |
^ |
按位異或 |
& |
按位與 |
<<,>> |
移位 |
+,- |
加法與減法 |
*,/,% |
乘法、除法與取余 |
+x,-x |
正負(fù)號(hào) |
~x |
按位翻轉(zhuǎn) |
** |
指數(shù) |
x.attribute |
屬性參考 |
x[index] |
下標(biāo) |
x[index:index] |
尋址段 |
f(arguments...) |
函數(shù)調(diào)用 |
(experession,...) |
綁定或元組顯示 |
[expression,...] |
列表顯示 |
{key:datum,...} |
字典顯示 |
'expression,...' |
字符串轉(zhuǎn)換 |
補(bǔ)充糾錯(cuò)
運(yùn)算符優(yōu)先級(jí)對(duì)照表說(shuō)明
?? 覆蓋語(yǔ)言
- ? Java
- ? C++
- ? C#
- ? PHP
- ? Python
- ? 更多...
?? 使用指南
1. 點(diǎn)擊下方 語(yǔ)言標(biāo)簽 快速定位 2. 表格中 顏色越深 優(yōu)先級(jí)越高 3. 遇到疑問(wèn)可點(diǎn)擊 查看示例
?? 學(xué)習(xí)技巧
- 先記憶 最高優(yōu)先級(jí)(如括號(hào))和 最低優(yōu)先級(jí)(如賦值)
- 對(duì)比相似運(yùn)算符:
++
vs+
,&&
vs||
- 使用口訣記憶法:如 "單算移比與,異或邏條賦"(C語(yǔ)言)
分享鏈接
你可能感興趣的工具
- IP子網(wǎng)掩碼計(jì)算器
- 網(wǎng)頁(yè)常用色彩
- UserAgent生成器
- 占位圖片生成器
- MD4算法加密工具
- JWT密匙生成器
- 屏幕PPI計(jì)算工具
- 英文字母大小寫(xiě)轉(zhuǎn)工具
- Photoshop快捷鍵大全
- Exce快捷鍵
- CSS代碼壓縮工具
- 卡密生成器
- 文本間隔生成工具
- IP檢測(cè)工具
- 雪花算法ID生成器
- MAC地址生成器
- 圖片裁剪工具
- HSV/CMYK互轉(zhuǎn)工具
- 網(wǎng)址鏈接批量生產(chǎn)器
- JSON轉(zhuǎn)Excel/Csv工具
- PEM文件生成器
- URL編碼解碼工具
- Java代碼格式化
- RC4加密解密工具
- 隨機(jī)IP地址生成器
- 下劃線/駝峰互轉(zhuǎn)
- PHP函數(shù)大全
- 百度推送工具
- JS代碼壓縮工具
- 一鍵采集器
- MQTT代碼生成工具
- UUID生成器
- 文字豎排工具
- 隨機(jī)數(shù)生成器
- WEB安全色
- XML代碼壓縮工具