Java/C语言/C++/Python/PHP运算符优先级
生活随笔
收集整理的這篇文章主要介紹了
Java/C语言/C++/Python/PHP运算符优先级
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
| 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 | = += -= *= /= %= &= ^= |= <<= >>= >>>= |
| :: | Scope resolution | Left-to-right |
| ++???-- | Suffix/postfix increment and decrement | |
| () | Function call | |
| [] | Array subscripting | |
| . | Element selection by reference | |
| ?> | Element selection through pointer | |
| ++???-- | 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 | |
| .*???->* | Pointer to member | Left-to-right |
| *???/???% | Multiplication, division, and remainder | |
| +???? | Addition and subtraction | |
| <<???>> | Bitwise left shift and right shift | |
| <???<= | For relational operators < and ≤ respectively | |
| >???>= | For relational operators > and ≥ respectively | |
| ==???!= | For relational = and ≠ respectively | |
| & | Bitwise AND | |
| ^ | Bitwise XOR (exclusive or) | |
| | | Bitwise OR (inclusive or) | |
| && | Logical AND | |
| || | Logical OR | |
| ?: | Ternary conditional | Right-to-Left |
| = | 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 | |
| throw | Throw operator (for exceptions) | |
| , | Comma | Left-to-right |
| ++?-- | 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) | |
| ++?-- | 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) | |
| *?/?% | Multiplication, division, and remainder | Left-to-right |
| +?? | Addition and subtraction | |
| <<?>> | Bitwise left shift and right shift | |
| <?<= | For relational operators < and ≤ respectively | |
| >?>= | For relational operators > and ≥ respectively | |
| ==?!= | For relational = and ≠ respectively | |
| & | Bitwise AND | |
| ^ | Bitwise XOR (exclusive or) | |
| | | Bitwise OR (inclusive or) | |
| && | Logical AND | |
| || | Logical OR | |
| ?: | Ternary conditional | Right-to-Left |
| = | 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 | |
| , | Comma | Left-to-right |
| 非結合 | clone new | clone 和 new |
| 左 | [ | array() |
| 非結合 | ++ -- | 遞增/遞減運算符 |
| 非結合 | ~ - (int) (float) (string) (array) (object) (bool) @ | 類型 |
| 非結合 | instanceof | 類型 |
| 右結合 | ! | 邏輯操作符 |
| 左 | * / % | 算術運算符 |
| 左 | + - . | 算術運算符 和 字符串運算符 |
| 左 | << >> | 位運算符 |
| 非結合 | < <= > >= <> | 比較運算符 |
| 非結合 | == != === !== | 比較運算符 |
| 左 | & | 位運算符 和 引用 |
| 左 | ^ | 位運算符 |
| 左 | | | 位運算符 |
| 左 | && | 邏輯運算符 |
| 左 | || | 邏輯運算符 |
| 左 | ? : | 三元運算符 |
| 右 | = += -= *= /= .= %= &= |= ^= <<= >>= | 賦值運算符 |
| 左 | and | 邏輯運算符 |
| 左 | xor | 邏輯運算符 |
| 左 | or | 邏輯運算符 |
| 左 | , | 多處用到 |
這個表給出Python的運算符優先級(從低到高).
從最低的優先級(最松散地結合)到最高的優先級(最緊密地結合)。
這意味著在一個表達式中,Python會首先計算表中較下面的運算符,然后在計算列在表上部的運算符。
| lambda | Lambda表達式 |
| or | 布爾“或” |
| and | 布爾“與” |
| not x | 布爾“非” |
| in,not in | 成員測試 |
| is,is not | 同一性測試 |
| <,<=,>,>=,!=,== | 比較 |
| | | 按位或 |
| ^ | 按位異或 |
| & | 按位與 |
| <<,>> | 移位 |
| +,- | 加法與減法 |
| *,/,% | 乘法、除法與取余 |
| +x,-x | 正負號 |
| ~x | 按位翻轉 |
| ** | 指數 |
| x.attribute | 屬性參考 |
| x[index] | 下標 |
| x[index:index] | 尋址段 |
| f(arguments...) | 函數調用 |
| (experession,...) | 綁定或元組顯示 |
| [expression,...] | 列表顯示 |
| {key:datum,...} | 字典顯示 |
| 'expression,...' | 字符串轉換 |
from:?http://tool.oschina.net/
總結
以上是生活随笔為你收集整理的Java/C语言/C++/Python/PHP运算符优先级的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 走向DBA[MSSQL篇] 从SQL语句
- 下一篇: PHP 手册 参考文档