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
運算子優先順序 C 運算子優先順序
c 運算子優先順序 優先順序運算子 描述方向1 scope resolution 範圍解析 left to right 2 suffix postfix increment and decrement 字首 字尾遞增和遞減 function call 函式呼叫 array subscripting ...
運算子優先順序表
c 語言運算子優先順序 詳細列表 運算子的優先順序 語言中,運算子的運算優先順序共分為15級。1 級最高,15級最低。在表示式中,優先順序較高的先於優先順序較低的進行運算。而在乙個運算量兩側的運算子優先順序相同時,則按運算子的結合性所規定的結合方向處理。運算子的結合性 語言中各運算子的結合性分為兩種...
運算子優先順序表
結合律 運算子 功能 使用形式左 全域性作用域 name左 類作用域 class name左 命名空間作用域 namespace name左.成員選擇 object.name 左 成員選擇 pointer member左 下標expr expr 左 函式呼叫 name expr list 左 型別構...