Expression Evaluation


Prev Tutorial Next Tutorial

Expression Evaluation in C++

In c language expression evaluation is mainly depends on priority and associativity.

Priority:

This represents the evaluation of expression starts from "what" operator.

Associativity:

It represents which operator should be evaluated first if an expression is containing more than one operator with same priority.

OperatorPriorityAssociativity
{}, (), []1Left to right
++, --, !2Right to left
*, /, %3Left to right
+, -4Left to right
<, <=, >, >=, ==, !=5Left to right
&&6Left to right
||7Left to right
?:8Right to left
=, +=, -=, *=, /=, %=9Right to left

Example 1:

evaluate-expression

Example 2:

evaluate-expression Prev Tutorial Next Tutorial
Prev Tutorial Next Tutorial

Advertisements




Facebook Likes

Advertisements