Although Java has the rule that the left operand of every binary operator is eva
ID: 3533379 • Letter: A
Question
Although Java has the rule that the left operand of every binary operator is evaluated before the right operand, most languages give the compiler the freedom to choose which operand is evaluated first. When expressions have side effects, the value of the expression can be different depending upon which order is used. Give an example in C++ of an expression whose value depends upon the evaluation order. Show the orders that produce different values and the values they produce. Explain what side effect is the expression contains.
Explanation / Answer
This ques. is related to associativity of operatotors.
actually we need to see the ambiguity concept
for ex.
consider equation-
a=3/2*5;
here there is tie b/w operators of same priority
so,we see associativity,both / and * are left to right associative
operator left right remark
/ 3 2 or 2 *5 left is unambiguos but right is not
* 3/2 or 2 5 right is unambiquos but left is not
hence / will be performed first because it is unambigous in left
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.