Appendix C. Operator Precedence Rules

The tables in this appendix summarize the precedence rules for operations in C++.

Standard Rules

Table C-1. Standard C++ precedence rules

Precedence

Operators

    

1

( )

[ ]

->

.

 
 

::

::*

->*

.*

 

2

!

~

++

--

(type)

 

- (unary)

* (dereference)

   
 

& (address of)

sizeof

   

3

* (multiply)

/

%

  

4

+

-

   

5

<<

>>

   

6

<

<=

>

>=

 

7

==

!=

   

8

& (bitwise AND)

    

9

^

    

10

|

    

11

&&

    

12

||

    

13

?:

    

14

=

+=

-=

etc.

 

15

,

    

Practical Subset of the Operator Precedence Rules

Table C-2. Practical operator precedence rules

Precedence

Operator

  

1

* (multiply)

/

%

2

+

-

 

Put parentheses around everything else.

Get Practical C++ Programming, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.