i2tutorials

Expressions

Expressions

 

An expression is a combination of variables, constants, and operators.

 

Examples:

 

SI=P*T*R/100 (a+b) c/d; 
a*b+c (d+x);
5*a+b+b*c; 
(a+b)*(x+y);

 

Evaluation of expressions:

 

An expression can be evaluated based on the precedence of operators, after the evaluation of an expression, the value of the expression is assigned to the variable.

 

Precedence of operators:

 

Operator precedence determines which operator will be performed first in a group of operators with different precedence.

 

Expressions

 

Highest Presidency :(,),*, /, %

Lowest Presidency: +, –

For instance, 5 + 3 * 2 is calculated as 5 + (3 * 2), giving 11, and not as (5 + 3) * 2, giving 16.

 

Example:

 

9-12/ (3+3)*(2-1)
9-12/6*1
9-2*1
9-2
7

 

 

Example:

 

9-(12/ ((3+3)*2)-1
9-(12/6*2)-1
9-(2*2)-1
9-4-1
5-1
4

 

 

Exit mobile version