运算符优先级总结

运算符优先级

    • Java 运算符优先级
    • C++ 运算符优先级
    • C语言运算符优先级
    • PHP 运算符优先级
    • Python 运算符优先级

Java 运算符优先级

运算符 优先级
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 = += -= *= /= %= &= ^= |= <<= >>= >>>=



C++ 运算符优先级

Precedence Operator Description Associativity
1 :: Scope resolution Left-to-right
2 ++ -- Suffix/postfix increment and decrement Left-to-right
() Function call Left-to-right
[] Array subscripting Left-to-right
. Element selection by reference Left-to-right
−> Element selection through pointer Left-to-right
3 ++ -- Prefix increment and decrement Right-to-left
+ Unary plus and minus Right-to-left
! ~ Logical NOT and bitwise NOT Right-to-left
(*type*) Type cast Right-to-left
* Indirection (dereference) Right-to-left
& Address-of Right-to-left
sizeof Size-of Right-to-left
new, new[] Dynamic memory allocation Right-to-left
delete, delete[] Dynamic memory deallocation Right-to-left
4 .* ->* Pointer to member Left-to-right
5 * / % Multiplication, division, and remainder Left-to-right
6 + Addition and subtraction Left-to-right
7 << >> Bitwise left shift and right shift Left-to-right
8 < <= For relational operators < and ≤ respectively Left-to-right
> >= For relational operators > and ≥ respectively Left-to-right
9 == != For relational = and ≠ respectively Left-to-right
10 & Bitwise AND Left-to-right
11 ^ Bitwise XOR (exclusive or) Left-to-right
12 ` ` Bitwise OR (inclusive or)
13 && Logical AND Left-to-right
14 ` `
15 ?: Ternary conditional Right-to-Left
16 = Direct assignment (provided by default for C++ classes) Right-to-Left
+= −= Assignment by sum and difference Right-to-Left
*= /= %= Assignment by product, quotient, and remainder Right-to-Left
<<= >>= Assignment by bitwise left shift and right shift Right-to-Left
&= ^= ` =` Assignment by bitwise AND, XOR, and OR
17 throw Throw operator (for exceptions) Right-to-Left
18 , Comma Left-to-right



C语言运算符优先级

Precedence Operator Description Associativity
1 ++ -- Suffix/postfix increment and decrement Left-to-right
() Function call Left-to-right
[] Array subscripting Left-to-right
. Structure and union member access Left-to-right
−> Structure and union member access through pointer Left-to-right
(*type*){*list*} Compound literal(C99) Left-to-right
2 ++ -- Prefix increment and decrement Right-to-left
+ Unary plus and minus Right-to-left
! ~ Logical NOT and bitwise NOT Right-to-left
(*type*) Type cast Right-to-left
* Indirection (dereference) Right-to-left
& Address-of Right-to-left
sizeof Size-of Right-to-left
_Alignof Alignment requirement(C11) Right-to-left
3 * / % Multiplication, division, and remainder Left-to-right
4 + Addition and subtraction Left-to-right
5 << >> Bitwise left shift and right shift Left-to-right
6 < <= For relational operators < and ≤ respectively Left-to-right
> >= For relational operators > and ≥ respectively Left-to-right
7 == != For relational = and ≠ respectively Left-to-right
8 & Bitwise AND Left-to-right
9 ^ Bitwise XOR (exclusive or) Left-to-right
10 ` ` Bitwise OR (inclusive or)
11 && Logical AND Left-to-right
12 ` `
13 ?: Ternary conditional Right-to-Left
14 = Simple assignment Right-to-Left
+= −= Assignment by sum and difference Right-to-Left
*= /= %= Assignment by product, quotient, and remainder Right-to-Left
<<= >>= Assignment by bitwise left shift and right shift Right-to-Left
&= ^= ` =` Assignment by bitwise AND, XOR, and OR
15 , Comma Left-to-right



PHP 运算符优先级

结合方向 运算符 附加信息
非结合 clone new clone 和 new
[ array()
非结合 ++ -- 递增/递减运算符
非结合 ~ - (int) (float) (string) (array) (object) (bool) @ 类型
非结合 instanceof 类型
右结合 ! 逻辑操作符
* / % 算术运算符
+ - . 算术运算符 和 字符串运算符
<< >> 位运算符
非结合 < <= > >= <> 比较运算符
非结合 == != === !== 比较运算符
& 位运算符 和 引用
^ 位运算符
` `
&& 逻辑运算符
`
? : 三元运算符
`= += -= *= /= .= %= &= = ^= <<= >>=`
and 逻辑运算符
xor 逻辑运算符
or 逻辑运算符
, 多处用到



Python 运算符优先级

运算符 描述
'expression,...' 字符串转换
{key:datum,...} 字典显示
[expression,...] 列表显示
(experession,...) 绑定或元组显示
f(arguments...) 函数调用
x[index:index] 寻址段
x[index] 下标
x.attribute 属性参考
** 指数
~x 按位翻转
+x,-x 正负号
*,/,% 乘法、除法与取余
+,- 加法与减法
<<,>> 移位
& 按位与
^ 按位异或
` `
<,<=,>,>=,!=,== 比较
is,is not 同一性测试
in,not in 成员测试
not x 布尔“非”
and 布尔“与”
or 布尔“或”
lambda Lambda表达式

你可能感兴趣的:(学习,windows,microsoft)