You are here

Abbreviated Precedence Chart for C++ Operators

19 January, 2016 - 11:41

An operator is a language-specific syntactical token (one or more symbols) that causes an action to be taken on one or more operands. The following item provides an abbreviated list of those C++ operators that are typically taught in a programming fundamentals course that teaches modular structured programming concepts.

The first column shows the precedence (the higher precedence is 1 or it goes first) and operators that have the same precedence also have the same associativity (the associativity is only listed once for the group of operators). Decrement is two minus signs, but some word processing software programs might have problems printing two minus signs and convert it to a double dash. Insertion (two < signs) and extraction (two > signs) might also have printing problems. These printing problems are noted in the comments with emphasized text.

Table 26.1 Operators

PR

OPERATOR NAME

SYMBOL(S)

COMMENTS

ASSOICIATIVITY

1

function call

()

 

Left to Right

1

index

[]

aka array index

 

2

class member

.

a period

Right to Left

2

postfx increment

++

unary

 

2

postfx decrement

-

unary, two minus signs

 

3

indirection

*

unary, aka dereference

Right to Left

3

address

&

unary

 

3

unary positive

+

unary, aka plus

 

3

unary negative

-

unary, aka minus

 

3

prefx increment

++

unary

 

3

prefx decrement

    -

unary, two minus signs

 

3

cast

(type)

unary

 

3

sizeof

sizeof (type)

unary

 

3

logical NOT

!

unary

 

4

multiply

*

 

Left to Right

4

divide

/

   

4

modulus

%

remainder

 

5

add

+

 

Left to Right

5

subtract

-

   

6

insertion

«

writing, two less than signs

Left to Right

6

extraction

»

reading, two greater than signs

 

7

less than

<

 

Left to Right

7

greater than

>

   

7

less than or equal to

<=

   

7

greater than or equal to

>=

   

8

equality

   ==

equal to

Left to Right

8

inequality

!=

not equal to

 

9

logical AND

&&

 

Left to Right

10

logical OR

||

 

Left to Right

11

conditional

? :

trinary

Left to Right

12

assignment

   =  

Right to Left

12

addition assignment

+=

   

12

subtraction assignment

-=

   

12

multiplication assignment

*=

   

12

division assignment

/=

   

12

modulus assignment

%=

   

13

sequence or comma

,

 

Left to Right