Associativity of operators

ajaykumarc137151 498 views 3 slides Jun 15, 2015
Slide 1
Slide 1 of 3
Slide 1
1
Slide 2
2
Slide 3
3

About This Presentation

In this document, i have explained about the operators precedence and if operators have same precedence,then how to solve those expressions etc

For more : http://comsciguide.blogspot.com/


Slide Content

For more : http://comsciguide.blogspot.com/2015/06/associativity-of-operators.html
Associativity of operators :
In general, expressions are the combination of operands and operators.
An operator is a symbol that tells the compiler to perform specific
mathematical or logical manipulations. We have different types of
operators which have some priority. According to priority, the
expressions are simplified.
For example :
a*b+c;
Here, operands are a,b,c and operators are *, +
From the table, we see that * have high priority than +. So the
expression is equal to ((a*b) +c).This tells that the * operator is
executed first and + next.
Suppose if an expression contains two or more equal priority operators,
then we have to use the Associativity of operators.
For example :
a * b + c / d - e

For more : http://comsciguide.blogspot.com/2015/06/associativity-of-operators.html
operands are a,b,c,d,e operators are * , + , / , -
From the priority table we get * and / have equal priority and also +
and – have equal priority.
We get the expression as (a * b) + ( c / d) - e
Now the problem arises which one in the bracket should first executed.
(a * b) or (c / d) and ((a * b) + (c / d)) or ((c / d) - e) i.e.
either + or - .
Associativity indicates in which order two operators of same
precedence (priority) executes first.
For example :
Suppose if we consider the expression a == b != c ,
Operands are a,b,c and operators are == , != .These two have same
priority. The associativity of both == and != is left to right i.e. the

For more : http://comsciguide.blogspot.com/2015/06/associativity-of-operators.html
expression in left is executed first and execution takes place towards
right. Thus a == b != c is equal to ((a == b) != c).
Now if we consider the above expression , As arithmetic operators
have left to right precedence, expression which is on the left is solved
first i.e. ((a * b) + (c / d)) and final expression is (((a * b ) + ( c / d )) - e)