Operator Precedence and Associativity in C++
In C++,operator precedencedetermines the order in which operators are evaluated in an
expression.Associativitydefines the direction in which operators of the same precedence
are evaluated (either from left to right or right to left).
Operator Precedence:-When an expression contains multiple operators,precedence
ecides which operator will be applied first. Operators with higher precedence are evaluated
d
before those with lower precedence.
Operator Associativity:-Associativitycomes into play when multiple operators with the
s ame precedence appear in an expression. It defines whether the evaluation happens from
left to right (left associativity) or right to left (right associativity).
OPERATORS OPERATORS PRECEDENCE ASSOCIATIVITY
( ) [] . -> LEFT--->RIGHT
- ++ -- ! size of(type) RIGHT--->LEFT
* / % LEFT--->RIGHT
+ - LEFT--->RIGHT
< <= > >= LEFT--->RIGHT
== != LEFT--->RIGHT
& & LEFT--->RIGHT
| | LEFT--->RIGHT
?: LEFT--->RIGHT
= += -= *= /= %= RIGHT--->LEFT
, LEFT--->RIGHT