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 questions
Answer options
A:

A. 20

B:

B. 11

Correct answer
C:

C. 14

D:

D. 24

Correct Answer:
B. B. 11
Explanation

Most 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.

Why Incorrect

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.

References

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 (+, -).

Scroll to Top