Advanced Programming Languages This is a discussion topic please go into detail
ID: 3664738 • Letter: A
Question
Advanced Programming Languages This is a discussion topic please go into detail discussing ***Question and instructions: 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? ***Please don't just copy something off the internet and answer the question. This has to be in your own words and not a long rambling from a website or document. (The teacher also has access to the internet sites your copying from) Please type your answer into chegg I am having a hard time reading handwritten documents. ***No hand written documents please*** Thank you for your helpExplanation / Answer
Consider the expression: 2 + 3 + 4. In this case, the first + will be evaluated, then the second +. With respect to both the operators, the left operands will be evaluated first, i.e., with respect to first + nothing to evaluate on the left hand side, and with respect to second +, the left operand + will be evaluated, which means 2 + 3 will be evaluated to 5, then the result will be added to 4 to make it 9.
Sometimes, the value depends on the evaluation order, when you use 2 different operators.
For example: 2 + 3 * 4 will lead to 20, when + is evaluated first, and * is evaluated next. Whereas, it can also lead to 14, when * is evaluated first, and + is evaluated next.
Sometimes, even when you use same operators, the evaluation order do matters.
For example: 8 / 2 / 2 will lead to 2, when leftside / is evaluated first, it will lead to 4/2 = 2. Whereas, it can also lead to 8, when the rightside / is evaluated first, 8/1 = 8.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.