Hierarchy of arithmetic operations in C: which option correctly places the higher-precedence operators before the lower-precedence ones?
-
A/ + * -
-
B* - / +
-
C+ - / *
-
D/ * + -
Answer
Correct Answer: / * + -
Explanation
Introduction / Context:Arithmetic operator precedence governs how C parses expressions without explicit parentheses. While * and / share the same precedence level (with % as well), they together outrank + and -. This question checks that you can order these groups correctly.
Given Data / Assumptions:
- Operators under consideration: +, -, , /.
- Standard C precedence and left-to-right associativity inside each level.
Concept / Approach:The multiplicative operators (, /, %) have higher precedence than the additive operators (+, -). Within each group the left-to-right associativity applies, but the exact sequence between * and / is not a precedence distinction—they are coequal. Any listing that shows the multiplicative group before the additive group reflects the correct hierarchy.
Step-by-Step Solution:Group 1 (higher): * and / (and %).Group 2 (lower): + and -.Choose the option that places the multiplicative group before the additive group.Option “/ * + -” satisfies this requirement.
Verification / Alternative check:Parenthesize a sample: 3 + 4 * 5 is parsed as 3 + (4 * 5), confirming multiplicative precedence over additive.
Why Other Options Are Wrong:
- Options placing + or - ahead of * or / invert the true hierarchy.
- The exact order between / and * is not significant for precedence; listing them together before + and - is the key.
Common Pitfalls:Assuming addition happens before multiplication, a common arithmetic misconception.
Final Answer:/ * + -.