OPERATOR PRECEDENCE IN C++
1. Operators at the top of the table have a higher precedence.
2. Operators within each level (box) have the same precedence.
3. Line numbers have been included for the sake of discussion.
|
Operator |
Description |
Associativity
|
1 2 3 4 |
() [] -> . |
Function call, type construction Array element reference Structure member pointer reference Structure member reference |
Left to right
|
5 6 7 8 9 10 11 12 13 14 |
++ -- - ! (type) or type () sizeof & * new delete |
Increment Decrement Unary minus Logical negation Type conversion Storage size Address of Indirection - pointer dereferencing Memory allocation Memory deallocation |
Right to Left |
15 16 17 |
* / % |
Multiplication Division Modulus (integer remainder) |
Left to right |
18 19 |
+ - |
Addition Subtraction |
Left to right |
20 21 22 23 |
< <= > >= |
Less-than Less-than-or-equal Greater-than Greater-than-or-equal |
Left to right |
24 25 |
== != |
Equality Inequality |
Left to right |
26 |
&& |
Logical AND |
Left to right |
27 |
|| |
Logical OR |
Left to right |
28 |
?: |
Conditional expression |
Right to left |
29 30 |
= += -= *= /= %= |
Assignment |
Right to left |