Also See more posts : www.comsciguide.blogspot.com
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
Also See more posts : www.comsciguide.blogspot.com
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 expression in left is
Also See more posts : www.comsciguide.blogspot.com
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)

Associativity of operators

  • 1.
    Also See moreposts : www.comsciguide.blogspot.com 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
  • 2.
    Also See moreposts : www.comsciguide.blogspot.com 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 expression in left is
  • 3.
    Also See moreposts : www.comsciguide.blogspot.com 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)