Foundations-of-Computer-Science practice question 8 of 15
What is the output of the expression 3 + 2 * 4 in most programming languages?
Full set: 71 questionsMost programming languages follow a standard order of operations, often referred to as operator precedence. In this hierarchy, multiplication () and division (/) have higher precedence than addition (+) and subtraction (-). Therefore, in the expression 3 + 2 4, the multiplication 2 4 is performed first, yielding 8. Then, the addition 3 + 8 is performed, resulting in a final value of 11.
A. The result 20 would come from (3 + 2) 4, which incorrectly prioritizes addition over multiplication, violating standard precedence rules.
C. The result 14 cannot be obtained through any standard interpretation of the mathematical operators in this expression.
D. The result 24 cannot be obtained through any standard interpretation of the mathematical operators in this expression.
1. Python Software Foundation. (n.d.). The Python Language Reference. Section 6.17, "Operator precedence." The documentation provides a table showing that (multiplication) has a higher precedence than + (addition). Retrieved from https://docs.python.org/3/reference/expressions.html#operator-precedence
2. Oracle. (n.d.). The Java™ Tutorials: Operators. In the "Summary of Operators" section, a table clearly lists the precedence of operators, showing multiplicative operators (, /, %) are evaluated before additive operators (+, -).
Keep practicing
Take the free Foundations-of-Computer-Science practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other Foundations-of-Computer-Science practice questions
- Question 1What is the purpose of a parameter in a function definition?
- Question 2What is the primary purpose of an operating system?
- Question 3Which action is taken if the first number is the lowest value in a selection sort?
- Question 4What will the expression fam[3:6] return?
- Question 5What will the output be of this line?
- Question 6Which aspect is excluded from a NumPy array’s structure?
