Across the following operator categories in C—(1) Relational, (2) Arithmetic, (3) Logical, (4) Assignment—what is the correct precedence order from highest to lowest?
-
A2134
-
B1234
-
C4321
-
D3214
Answer
Correct Answer: 2134
Explanation
Introduction / Context:Reasoning about complex expressions often requires knowing which classes of operators bind tighter than others. C groups operators by precedence levels. This question asks you to order four broad classes correctly.
Given Data / Assumptions:
- Classes: Arithmetic (2), Relational (1), Logical (3), Assignment (4).
- Unary operators are not part of this question; we consider the usual binary forms.
Concept / Approach:Arithmetic operators (+, -, *, /, %) have higher precedence than relational operators (<, <=, >, >=). Relational operators, in turn, bind tighter than logical operators (&&, ||). The assignment operators (=, +=, etc.) are among the lowest. Therefore, the order from highest to lowest is: Arithmetic → Relational → Logical → Assignment.
Step-by-Step Solution:Place Arithmetic first (2).Next place Relational (1).Then Logical (3).Finally Assignment (4).Concatenate: 2 1 3 4 → 2134.
Verification / Alternative check:Consider 3 + 2 > 4 && flag = 1; The arithmetic part 3 + 2 is grouped first, then the relational comparison, then logical AND, and only then the assignment executes.
Why Other Options Are Wrong:
- 1234, 3214, 4321 place one or more categories out of order with respect to the C precedence table.
Common Pitfalls:Confusing evaluation order with precedence; logical operators short-circuit but still have lower precedence than relational operators.
Final Answer:2134.