C 運算子優先順序

2021-06-05 04:25:50 字數 2784 閱讀 8071

運算子優先順序:

網域名稱解析符最高;

然後是前置增量符/前置減量符/括號/陣列下標/指標訪問符;

單目運算子比雙目運算子高;

算術雙目比其它雙目高;

位運算高於關係運算;

關係運算高於按位運算(&, |, ^);

按位運算高於邏輯運算;

三目的只有乙個條件運算(?:),低於邏輯運算

賦值運算僅比 , (順序運算)高

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

typeid()run-time type information (see typeid

)const_casttype cast (see const_cast

)dynamic_casttype cast (see dynamic_cast

)reinterpret_casttype cast (see reinterpret_cast

)static_casttype cast (see static_cast)3

++--prefix increment and decrement

right-to-left

+-unary plus and minus

!~logical not and bitwise not

(type)type cast

*indirection (dereference)

&address-of

sizeofsize-of

new,newdynamic memory allocation

delete,deletedynamic 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

17throwthrow operator (exceptions throwing)

18,comma

left-to-right

運算子優先順序 C 運算子優先順序

c 運算子優先順序 優先順序運算子 描述方向1 scope resolution 範圍解析 left to right 2 suffix postfix increment and decrement 字首 字尾遞增和遞減 function call 函式呼叫 array subscripting ...

運算子優先順序 Python 運算子優先順序

python 運算子優先順序 運算子描述 lambda lambda表示式 or布林 或 and布林 與 not x 布林 非 in,not in 成員測試 is,is not 同一性測試 比較 按位或 按位異或 按位與 移位 加法與減法 乘法 除法與取餘 x,x 正負號 x 按位翻轉 指數 x.a...

運算子優先順序 PHP運算子優先順序

php運算子優先順序 結合方向 運算子附加資訊 非結合clone new clone 和 new左 array 非結合 遞增 遞減運算子 非結合 int float string array object bool 型別非結合 instanceof 型別右結合 邏輯操作符 左 算術運算子 左 算術運...