A.1. Operator Precedence

Operators are shown in decreasing order of precedence from top to bottom (Fig. A.1).

Figure A.1. Operator precedence and associativity chart.


[Pages 1229 - 1230]

Operator

Type

Associativity

::

binary scope resolution

left to right

::

unary scope resolution

 

()

parentheses

left to right

[]

array subscript

 

.

member selection via object

 

->

member selection via pointer

 

++

unary postfix increment

 

--

unary postfix decrement

 

typeid

runtime type information

 

dynamic_cast < type >

runtime type-checked cast

 

static_cast< type >

compile-time type-checked cast

 

reinterpret_cast< type >

cast for nonstandard conversions

 

const_cast< type >

cast away const-ness

 

++

unary prefix increment

right to left

--

unary prefix decrement

 

+

unary plus

 

-

unary minus

 

!

unary logical negation

 

~

unary bitwise complement

 

sizeof

determine size in bytes

 

&

address

 

*

dereference

 

new

dynamic memory allocation

 

new[]

dynamic array allocation

 

delete

dynamic memory deallocation

 

delete[]

dynamic array deallocation

 

( type )

C-style unary cast

right to left

.*

pointer to member via object

left to right

->*

pointer to member via pointer

 

*

multiplication

left to right

/

division

 

%

modulus

 

+

addition

left to right

-

subtraction

 

<<

bitwise left shift

left to right

>>

bitwise right shift

 

<

relational less than

left to right

<=

relational less than or equal to

 

>

relational greater than

 

>=

relational greater than or equal to

 

==

relational is equal to

left to right

!=

relational is not equal to

 

&

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

?:

ternary conditional

right to left

=

assignment

right to left

+=

addition assignment

 

-=

subtraction assignment

 

*=

multiplication assignment

 

/=

division assignment

 

%=

modulus assignment

 

&=

bitwise AND assignment

 

^=

bitwise exclusive OR assignment

 

|=

bitwise inclusive OR assignment

 

<<=

bitwise left-shift assignment

 

>>=

bitwise right-shift assignment

 

,

comma

left to right

Категории