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

The C++ language includes all C operators and adds several new operators. Operators specify an evaluation to be performed on one of the following:

·         One operand (unary operator)

·         Two operands (binary operator)

·         Three operands (ternary operator)

Operators follow a strict precedence, which defines the evaluation order of expressions containing these operators. Operators associate with either the expression on their left or the expression on their right; this is called "associativity." The following table shows the precedence and associativity of C++ operators (from highest to lowest precedence). Operators in the same segment of the table have equal precedence and are evaluated in the given order in an expression unless explicitly forced by parentheses.

Operator

Name or Meaning

Associativity

::

Scope resolution

None

.

Member selection (object)

Left to right

–>

Member selection (pointer)

Left to right

[ ]

Array subscript

Left to right

( )

Function call member initialization

Left to right

++

Postfix increment

Left to right

––

Postfix decrement

Left to right

typeid( )

type name

Left to right

const_cast

Type cast (conversion)

Left to right

dynamic_cast

Type cast (conversion)

Left to right

reinterpret_cast

Type cast (conversion)

Left to right

static_cast

Type cast (conversion)

Left to right

sizeof

Size of object or type

Right to left

++

Prefix increment

Right to left

––

Prefix decrement

Right to left

~

One's complement

Right to left

!

Logical not

Right to left

Unary minus

Right to left

+

Unary plus

Right to left

&

Address-of

Right to left

*

Indirection

Right to left

new

Create object

Right to left

delete

Destroy object

Right to left

()

Cast

Right to left

.*

Pointer-to-member (objects)

Left to right

–>*

Pointer-to-member (pointers)

Left to right

*

Multiplication

Left to right

/

Division

Left to right

%

Modulus

Left to right

+

Addition

Left to right

Subtraction

Left to right

<<  

Left shift

Left to right

>>  

Right shift

Left to right

<  

Less than

Left to right

>  

Greater than

Left to right

<=

Less than or equal to

Left to right

>=

Greater than or equal to

Left to right

==

Equality

Left to right

!=

Inequality

Left to right

&

Bitwise AND

Left to right

^

Bitwise exclusive OR

Left to right

|

Bitwise inclusive OR

Left to right

&&

Logical AND

Left to right

||

Logical OR

Left to right

e1?e2:e3

Conditional

Right to left

=

Assignment

Right to left

*=

Multiplication assignment

Right to left

/=

Division assignment

Right to left

%=

Modulus assignment

Right to left

+=

Addition assignment

Right to left

–=

Subtraction assignment

Right to left

<<=

Left-shift assignment

Right to left

>>=

Right-shift assignment

Right to left

&=

Bitwise AND assignment

Right to left

|=

Bitwise inclusive OR assignment

Right to left

^=

Bitwise exclusive OR assignment

Right to left

throw expr

throw expression

Right to left

,

Comma

Left to right

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值