Precedence | Operator | Description | Example | Associativity |
---|---|---|---|---|
1 |
() [] -> . :: ++ -- |
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 right |
2 |
! ~ ++ -- - + * & (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 right |
4 |
* / % |
Multiplication Division Modulus |
int i = 2 * 4; float f = 10 / 3; int rem = 4 % 3; |
left to right |
5 |
+ - |
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 right |
8 |
== != |
Comparison equal-to Comparison not-equal-to |
if( i == 42 ) ... if( i != 42 ) ... |
left to right |
9 | & | Bitwise AND | flags = flags & 42; | left to right |
10 | ^ | Bitwise exclusive OR | flags = flags ^ 42; | left to right |
11 | | | 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 left |
15 |
= += -= *= /= %= &= ^= |= <<= >>= |
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 left |
16 | , | Sequential evaluation operator | for( i = 0, j = 0; i < 10; i++, j++ ) ... | left to right |
C++符号优先级(详细整理)
2021-01-05 11:41C++教程网 C/C++
C++符号优先级,我详细整理了一下。需要的朋友可以过来参考下。希望对大家有所帮助
延伸 · 阅读
- 2022-03-11C++多线程之互斥锁与死锁
- 2022-03-11C++学习之线程详解
- 2022-03-11如何通过C++求出链表中环的入口结点
- 2022-03-11一篇文章了解c++中的new和delete
- 2022-03-11C/C++ Qt数据库SqlRelationalTable关联表详解
- 2022-03-11C++中signed main和int main的区别
- C/C++
浅谈防不胜防的unsigned int的运算
下面小编就为大家带来一篇浅谈防不胜防的unsigned int的运算。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧...
- C/C++
C++输入一个字符串,把其中的字符按照逆序输出的两种方法解析
以下是对C++中输入一个字符串,把其中的字符按照逆序输出的两种方法进行了详细的分析介绍,需要的朋友可以过来参考下...
- C/C++
Visual Studio C++指针靠前靠后的问题全面解析
这篇文章主要介绍了Visual Studio C++指针靠前靠后的问题全面解析,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可...
- C/C++
构造函数不能声明为虚函数的原因及分析
构造函数不需要是虚函数,也不允许是虚函数,因为创建一个对象时我们总是要明确指定对象的类型,尽管我们可能通过实验室的基类的指针或引用去访问...
- C/C++
深入分析C++中deque的使用
本篇文章介绍了,深入分析C++中deque的使用。需要的朋友参考下...
- C/C++
Opencv绘制最小外接矩形、最小外接圆
这篇文章主要为大家详细介绍了Opencv绘制最小外接矩形、最小外接圆的方法,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以...
- C/C++
C语言实现随机抽奖程序
这篇文章主要为大家详细介绍了C语言实现随机抽奖程序,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...
- C/C++
如何用C语言、Python实现栈及典型应用
本文先通过实例分别介绍了如何用C语言、Python实现栈,后又介绍栈的典型应用,对大家学习栈很有借鉴参考价值,下面一起来看看吧。...