`

C++ 运算符优先级列表

阅读更多

The operators at the top of this list are evaluated first. Operators within a group have the same precedence. All operators have left-to-right associativity unless otherwise noted.

 

Precedence Operator Description Example Overloadable Associativity
1 :: Scope resolution operator Class::age = 2; no left to right
2 () Function call printf(“Hello world\n”); yes left to right
() Member initalization c_tor(int x, int y) : _x(x), _y(y * 10) {} yes
[] Array access array[4] = 2; yes
-> Member access from a pointer ptr->age = 34; yes
. Member access from an object obj.age = 34; no
++ Post-increment for (int i = 0; i < 10; i++) cout << i; yes
-- Post-decrement for (int i = 10; i > 0; i--) cout << i; yes
dynamic_cast Runtime-checked type conversion Y& y = dynamic_cast<Y&>(x); no
static_cast Unchecked type conversion Y& y = static_cast<Y&>(x); no
reinterpret_cast Reinterpreting type conversion int const* p = reinterpret_cast<int const*>(0x1234); no
const_cast Cast away/Add constness int* q = const_cast<int*>(p); no
typeid Get type information std::type_info const& t = typeid(x); no
3 ! Logical negation if (!done) ... yes right to left
not Alternate spelling for !
~ Bitwise complement flags = ~flags; yes
compl Alternate spelling for ~
++ Pre-increment for (i = 0; i < 10; ++i) cout << i; yes
-- Pre-decrement for (i = 10; i > 0; --i) cout << i; yes
- Unary minus int i = -1; yes
+ Unary plus int i = +1; yes
* Dereference int data = *intPtr; yes
& Address of int *intPtr = &data; yes
sizeof Size (of the type) of the operand in bytes size_t s = sizeof(int); no
new Dynamic memory allocation long* pVar = new long; yes
new [] Dynamic memory allocation of array long* array = new long[20]; yes
delete Deallocating the memory delete pVar; yes
delete [] Deallocating the memory of array delete [] array; yes
(type) Cast to a given type int i = (int)floatNum; yes
4 ->* Member pointer selector ptr->*var = 24; yes left to right
.* Member object selector obj.*var = 24; no
5 * Multiplication int i = 2 * 4; yes left to right
/ Division float f = 10.0 / 3.0; yes
% Modulus int rem = 4 % 3; yes
6 + Addition int i = 2 + 3; yes left to right
- Subtraction int i = 5 - 1; yes
7 << Bitwise shift left int flags = 33 << 1; yes left to right
>> Bitwise shift right int flags = 33 >> 1; yes
8 < Comparison less-than if (i < 42) ... yes left to right
<= Comparison less-than-or-equal-to if (i <= 42) ... yes
> Comparison greater-than if (i > 42) ... yes
>= Comparison greater-than-or-equal-to if (i >= 42) ... yes
9 == Comparison equal-to if (i == 42) ... yes left to right
eq Alternate spelling for ==
!= Comparison not-equal-to if (i != 42) ... yes
not_eq Alternate spelling for !=
10 & Bitwise AND flags = flags & 42; yes left to right
bitand Alternate spelling for &
11 ^ Bitwise exclusive OR (XOR) flags = flags ^ 42; yes left to right
xor Alternate spelling for ^
12 | Bitwise inclusive (normal) OR flags = flags | 42; yes left to right
bitor Alternate spelling for |
13 && Logical AND if (conditionA && conditionB) ... yes left to right
and Alternate spelling for &&
14 || Logical OR if (conditionA || conditionB) ... yes left to right
or Alternate spelling for ||
15 ? : Ternary conditional (if-then-else) int i = a > b ? a : b; no right to left
16 = Assignment operator int a = b; yes right to left
+= Increment and assign a += 3; yes
-= Decrement and assign b -= 4; yes
*= Multiply and assign a *= 5; yes
/= Divide and assign a /= 2; yes
%= Modulo and assign a %= 3; yes
&= Bitwise AND and assign flags &= new_flags; yes
and_eq Alternate spelling for &=
^= Bitwise exclusive or (XOR) and assign flags ^= new_flags; yes
xor_eq Alternate spelling for ^=
|= Bitwise normal OR and assign flags |= new_flags; yes
or_eq Alternate spelling for |=
<<= Bitwise shift left and assign flags <<= 2; yes
>>= Bitwise shift right and assign flags >>= 2; yes
17 throw throw exception throw EClass(“Message”); no
18 , Sequential evaluation operator for (i = 0, j = 0; i < 10; i++, j++) ... yes left to right
分享到:
评论

相关推荐

    C++ 运算符优先级列表 pdf

    ### C++ 运算符优先级详解 在编程语言中,了解运算符的优先级对于正确解析表达式至关重要。在C++中,不同的运算符有不同的优先级,这直接影响到表达式的计算顺序。本文将详细介绍C++中的运算符优先级,并通过具体的...

    C++运算符优先级表

    C++运算符优先级表 C++ 运算符优先级表是一份非常重要的参考资源,对于C++开发者来说是必不可少的。本文将详细介绍C++运算符优先级表,并对每个运算符进行解释。 一、括号运算符 括号运算符的优先级最高,包括...

    C_C++运算符优先级列表.pdf

    ### C/C++ 运算符优先级列表解析 在编程语言C和C++中,运算符的优先级决定了表达式的计算顺序。理解这些运算符及其优先级对于编写正确的程序至关重要。下面将根据提供的资料详细解释C/C++中的运算符、它们的优先级...

    C++运算符优先级 .pdf

    C++运算符优先级整理

    C++实战篇:运算符优先级

    C++实战篇:运算符优先级 C++实战篇:运算符优先级 C++实战篇:运算符优先级 C++实战篇:运算符优先级 C++实战篇:运算符优先级 C++实战篇:运算符优先级 C++实战篇:运算符优先级 C++实战篇:运算符优先级 C++实战...

    C++运算符优先级

    c++的运算符优先级 很有用的东西 对编程不是很熟悉的人可以看看 对于熟悉变成的人来说 也可以作为参考

    c和c++运算符优先级

    ### C和C++运算符优先级详解 在编程语言中,理解运算符的优先级是至关重要的,因为这直接影响到表达式的计算顺序和结果。C和C++作为两种广泛使用的编程语言,它们共享大部分相同的运算符及其优先级规则,但也有细微...

    C++运算符优先级汇总表

    C++运算符优先级是编程过程中非常重要的概念,它规定了不同运算符在表达式中的执行顺序。了解这些优先级可以帮助我们正确地编写和理解代码,避免因运算顺序错误而导致的程序异常。以下是对C++中各类运算符优先级的...

    C++运算符优先级表格

    C++运算符优先级以及使用方法功能介绍等相关的一体化信息表格 摘录自C++ primer 第五版 第四章 12节 页数147

    c++运算符优先级,word版本表格

    C++ 运算符优先级详解 C++ 语言提供了多种运算符,每种运算符都有其优先级和结合律。了解运算符的优先级和结合律对于编写正确的 C++ 程序至关重要。 结合律 在 C++ 中,运算符的结合律是指当多个运算符出现在同一...

    C++运算符优先级及结合性

    在原版【C++运算符优先级及结合性表】的基础上进行优化,更利于观看和识别

    c++ 运算符优先级 运算符优先级 备赛

    ### C++运算符优先级详解 在C++编程中,理解和掌握运算符的优先级对于编写高效、可靠的代码至关重要。本文将详细介绍C++中的运算符优先级,并通过具体示例来帮助读者更好地理解这些概念。 #### 第一级别:作用域...

    运算符优先级总结(C++)

    ### 运算符优先级总结(C++) 在C++编程语言中,了解运算符的优先级对于编写高效且无误的代码至关重要。本篇文章基于提供的文件信息进行深入解析,帮助读者更好地掌握C++中的运算符优先级及其结合性。 #### 一、...

    C++运算符优先级 满页打印

    ### C++运算符优先级详解 #### 一、引言 在C++编程语言中,了解运算符的优先级和结合性对于编写清晰且高效的代码至关重要。错误地理解或忽略这些规则可能导致意料之外的结果。本文将详细介绍C++中的运算符优先级,...

    C and C++运算符优先级等级口诀.docx

    以下是对C和C++运算符优先级的详细说明: 1. **括号运算符** (最高优先级,左结合) - `( )`圆括号用于分组计算,无论其内部的运算符优先级如何,都会先进行计算。 - `[ ]`下标运算符,如 `array[index]`,用于...

    运算符优先级表

    包含了全部的C++运算符,内容非常详细,十分清晰,易懂。

    c++运算符优先级

    c++运算符优先级

Global site tag (gtag.js) - Google Analytics