Operator Precedence Table in C++
The operator precedence table in C++ is a table that lists the operators in order of their precedence level. Operators with higher precedence are evaluated before operators with lower precedence. This table also includes the associativity of the operators, which determines the order in which operators of the same precedence are processed.
The operators are listed from top to bottom, in descending precedence
Operator | Name | Associativity |
---|---|---|
() [] -> . | Function call, Subscript, Member access | Left |
++ — | Increment/Decrement | Right |
! ~ – + | Logical/Bitwise NOT, Unary plus/minus | Right |
* / % | Multiplication, Division, Modulus | Left |
+ – | Addition, Subtraction | Left |
<< >> | Bitwise shift | Left |
< <= > >= | Relational operators | Left |
== != | Equality operators | Left |
& | Bitwise AND | Left |
^ | Bitwise XOR | Left |
| | Bitwise OR | Left |
&& | Logical AND | Left |
|| | Logical OR | Left |
?: | Ternary conditional | Right |
= += -= *= /= %= &= ^= |= <<= >>= | Assignment and compound assignment | Right |
, | Comma | Left |
Operator Precedence and Associativity in C++
In C++,operator precedence and associativity are important concepts that determine the order in which operators are evaluated in an expression. Operator precedence tells the priority of operators, while associativity determines the order of evaluation when multiple operators of the same precedence level are present.