運算子優先順序列表

2021-04-28 10:53:46 字數 3341 閱讀 2474

precedence

operator

description

example

associativity1()

->.::

++--

grouping operator

array access

member access from a pointer

member access from an object

scoping operator

post-increment

post-decrement

(a + b) / 4;

array[4] = 2;

ptr->age = 34;

obj.age = 34;

class::age = 2;

for( i = 0; i < 10; i++ ) ...

for( i = 10; i > 0; i-- ) ...

left to right2!

~++---

+*&(type)

sizeof

logical negation

bitwise complement

pre-increment

pre-decrement

unary minus

unary plus

dereference

address of

cast to a given type

return size in bytes

if( !done ) ...

flags = ~flags;

for( i = 0; i < 10; ++i ) ...

for( i = 10; i > 0; --i ) ...

int i = -1;

int i = +1;

data = *ptr;

address = &obj;

int i = (int) floatnum;

int size = sizeof(floatnum);

right to left

3->*

.*member pointer selector

member pointer selector

ptr->*var = 24;

obj.*var = 24;

left to right4*

/%multiplication

division

modulus

int i = 2 * 4;

float f = 10 / 3;

int rem = 4 % 3;

left to right5+

-addition

subtraction

int i = 2 + 3;

int i = 5 - 1;

left to right

6<<

>>

bitwise shift left

bitwise shift right

int flags = 33 << 1;

int flags = 33 >> 1;

left to right

7<

<=

>

>=

comparison less-than

comparison less-than-or-equal-to

comparison greater-than

comparison geater-than-or-equal-to

if( i < 42 ) ...

if( i <= 42 ) ...

if( i > 42 ) ...

if( i >= 42 ) ...

left to right8==

!=comparison equal-to

comparison not-equal-to

if( i == 42 ) ...

if( i != 42 ) ...

left to right9&

bitwise and

flags = flags & 42;

left to right10^

bitwise exclusive or

flags = flags ^ 42;

left to right11|

bitwise inclusive (normal) or

flags = flags | 42;

left to right

12&&

logical and

if( conditiona && conditionb ) ...

left to right

13||

logical or

if( conditiona || conditionb ) ...

left to right

14? :

ternary conditional (if-then-else)

int i = (a > b) ? a : b;

right to left15=

+=-=

*=/=

%=&=

^=|=

<<=

>>=

assignment operator

increment and assign

decrement and assign

multiply and assign

divide and assign

modulo and assign

bitwise and and assign

bitwise exclusive or and assign

bitwise inclusive (normal) or and assign

bitwise shift left and assign

bitwise shift right and assign

int a = b;

a += 3;

b -= 4;

a *= 5;

a /= 2;

a %= 3;

flags &= new_flags;

flags ^= new_flags;

flags |= new_flags;

flags <<= 2;

flags >>= 2;

right to left16,

sequential evaluation operator

for( i = 0, j = 0; i < 10; i++, j++ ) ...

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 型別右結合 邏輯操作符 左 算術運算子 左 算術運...