The C ++ language expressions and operators

Expressions and statements

Expressions are formed from operators and operands, the operand itself also be an expression.

Semicolon after expression constitutes statement.

In C ++ operator precedence

  • Operator determines the order of priority values ​​for the operator.
  • C ++ operator is divided into 18 groups. The smaller the group the higher the priority.
  • If two operators are used in the same operand, the first application of the highest priority operator.
  • If two operators have the same priority level, the use of C ++ binding rules to determine which operator to binding.
  • Binding of the same priority and the same set of operators.
  • Associativity from left to right than the left represents the first application of most operators, and right-to-left combination represents the first application of the rightmost operator.
  • Calculation, () has the highest priority, arithmetic> Relations> Logic> Conditions> assignment> comma (not absolute).
  • Unary> binary operator> ternary operator (not absolute).
  • Clear and specific binding of priority, you can add ().
Operators Associativity meaning
The first priority group
::   Scope resolution operator
The second set of priorities
(expression)   Packet
() L-R Function call
()   Configuration values, i.e. type (expr)
[]   Array subscript
->   Indirect member operator
.   Direct member operator
const_cast   Special type conversion
dynamic_cast   Special type conversion
reinterpret_cast   Special type conversion
static_cast   Special type conversion
typeid   Type Id
++  

1 plus operator, Suffix

--   Save Operators 1, Suffix
The third priority group (all unary)
R-L Logical NOT
~   Non-bit
+  

Unary plus, a positive sign

-   Unary minus, minus
++   1 plus operator, the prefix
--   Save 1 operator, the prefix
&   address
*   Dereferencing (indirect value)
()   Type conversion, that (type) expr
sizeof   The length, in bytes
new   Dynamic memory allocation
new []   Dynamically allocated arrays
delete   Dynamic memory release
delete  

Dynamic Array release

The fourth priority group
.* L-R Members dereference
->*   Indirect members dereference
A fifth priority group (all binary operator)
* L-R Multiply
/   except
%   Modulus (remainder)
Priority sixth group (all binary operator)
+ L-R plus
-   Less
Priority seventh group
<< L-R The left
>>   Right
Priority eighth group
< L-R Less than
<=   less than or equal to
>=   greater than or equal to
>   more than the
Priority ninth group
== L-R equal
!=   not equal to
Priority Group 10 (unary)
& L-R Bitwise AND
优先级第十一组
^ L-R 按位 XOF(异或)
优先级第十二组
| L-R 按位 OR
优先级第十三组
&& L-R 逻辑 AND
优先级第十四组
|| L-R 逻辑 OR
优先级第十五组
?: R-L 条件
优先级第十六组
= R-L 简单赋值
*=   乘并赋值
/=   除并赋值
%=   求模并赋值
+=   加并赋值
-=   减并赋值
&=   按位 AND 并赋值
^=   按位 XOR 并赋值
|=   按位 OR 并赋值
<<=   左移并赋值
>>=  

右移并赋值

优先级第十七组
throw L-R 引发异常
优先级第十八组
, L-R 将两个表达式合并为一个
发布了77 篇原创文章 · 获赞 5 · 访问量 4891

Guess you like

Origin blog.csdn.net/SAKURASANN/article/details/104419328