C/C++运算符优先级
来源:互联网 发布:微信java关注推送事件 编辑:程序博客网 时间:2024/06/14 12:35
http://en.cppreference.com/w/cpp/language/operator_precedence
The following table lists the precedence and associativity of C++ operators. Operators are listed top to bottom, in descending precedence.
::
Scope resolutionLeft-to-right++
--
Suffix/postfix increment and decrement()
Function call[]
Array subscripting.
Element selection by reference−>
Element selection through pointer++
--
Prefix increment and decrementRight-to-left+
−
Unary plus and minus!
~
Logical NOT and bitwise NOT(type)
Type cast*
Indirection (dereference)&
Address-ofsizeof
Size-ofnew
, new[]
Dynamic memory allocationdelete
, delete[]
Dynamic memory deallocation.*
->*
Pointer to memberLeft-to-right*
/
%
Multiplication, division, and remainder+
−
Addition and subtraction<<
>>
Bitwise left shift and right shift<
<=
For relational operators < and ≤ respectively>
>=
For relational operators > and ≥ respectively==
!=
For relational = and ≠ respectively&
Bitwise AND^
Bitwise XOR (exclusive or)|
Bitwise OR (inclusive or)&&
Logical AND||
Logical OR?:
Ternary conditionalRight-to-left=
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 ORthrow
Throw operator (for exceptions),
CommaLeft-to-rightWhen parsing an expression, an operator which is listed on some row will be bound tighter (as if by parentheses) to its arguments than any operator that is listed on a row further below it. For example, the expressionsstd::cout<<a&b and *p++ are parsed as(std::cout<<a)&b and *(p++), and not as std::cout<<(a&b) or (*p)++.
Operators that are in the same cell (there may be several rows of operators listed in a cell) are evaluated with the same precedence, in the given direction. For example, the expressiona=b=c is parsed asa=(b=c), and not as (a=b)=c because of right-to-left associativity.
An operator's precedence is unaffected by overloading.
Notes
The standard itself doesn't specify precedence levels. They are derived from the grammar.
const_cast,static_cast, dynamic_cast, reinterpret_cast and typeid are not included since they are never ambiguous.
Some of the operators have alternate spellings (e.g., and for&&
, or for ||
,not for !
, etc.).
See also
Order of evaluation of operator arguments at run time.
decrementarithmeticlogicalcomparisonmember
accessother
a = b
a = rvalue
a += b
a -= b
a *= b
a /= b
a %= b
a &= b
a |= b
a ^= b
a <<= b
a >>= b
++a
--a
a++
a--
+a
-a
a + b
a - b
a * b
a / b
a % b
~a
a & b
a | b
a ^ b
a << b
a >> b
!a
a && b
a || b
a == b
a != b
a < b
a > b
a <= b
a >= b
a[b]
*a
&a
a->b
a.b
a->*b
a.*b
a(...)
a, b
(type) a
? :
static_cast converts one type to another compatible type
dynamic_cast converts virtual base class to derived class
const_cast converts type to compatible type with differentcv qualifiers
reinterpret_cast converts type to incompatible type
new allocates memory
delete deallocates memory
sizeof queries the size of a type
sizeof... queries the size of aparameter pack (since C++11)
typeid queries the type information of a type
noexcept checks if an expression can throw an exception(since C++11)
alignof queries alignment requirements of a type(since C++11)
- c 运算符 优先级
- c 运算符 优先级
- C运算符优先级
- c运算符优先级
- C运算符优先级
- C运算符优先级
- C运算符优先级
- c运算符优先级
- c运算符优先级
- C运算符优先级
- C运算符优先级
- C运算符优先级
- C运算符优先级
- c运算符优先级
- C 运算符优先级
- C运算符优先级
- c 运算符 优先级
- C运算符优先级
- C++ Operator Precedence 运算符优先级
- 平凡中的哲理
- C++ 人工神经网络类 。。有错误。。先留着吧。
- 大数据和内存计算提升数据中心效率
- 输入a和b两个整数,按先大后小的顺序输出a和b。(用指针变量处理)
- C/C++运算符优先级
- CSDN技术博客文章模板
- 新浪微博登录数据库应该存什么值?
- webconfig中appSettings和connectionStrings的使用
- 对输入的两个整数按大小顺序输出。
- 需要谈谈的系列三 产业分析测试目前地位(一)
- 输入a,b,c三个整数,按由大到小顺序输出。(用3个指针变量指向3个整形变量,然后用swap函数来实现互换3个整型变量的值)
- The Trip. 2007
- 用指针变量指向数组元素。