C++ Precedence and Associativity

Precedence and Associativity

Say, you have a mathematical operation like below :

which operations will be performed first and which order ?

  • Set of rules to follow when we have multiple operators in the same expression.

Check this table here

The following table lists the precedence and associativity of C++ operators. Operators are listed top to bottom, in descending precedence.

Example :

Output : 30

We can always use parenthesis () to explicitly specify which operations you want to perform.

Order of Evaluation

Order of evaluation between different expressions is undefined in C++. We can’t guarantee which expression is evaluated first.

Summary