Difficulty: Medium
Correct Answer: 12, 1, 12
Explanation:
Introduction / Context:
This example tests detailed precedence and associativity across bitwise AND (&), XOR (^), OR (|), and logical AND (&&). Knowing that bitwise operators have higher precedence than logical && and that & binds more tightly than | is essential.
Given Data / Assumptions:
Concept / Approach:
Parse each expression with precedence rules, reduce bitwise operations to integers, then evaluate logical && which yields 0 or 1. Finally, print the results.
Step-by-Step Solution:
Expr1: i | j & j | i → i | (j & j) | i → 4 | 8 | 4 = 12.Expr2: i | j && j | i → (i | j) && (j | i) because | has higher precedence than && → (12) && (12) → 1.Expr3: i ^ j → 0100 ^ 1000 = 1100 → 12.
Verification / Alternative check:
Add parentheses explicitly to match the parsing above and re-run; you will see identical outputs: 12, 1, 12.
Why Other Options Are Wrong:
They assume different precedence (e.g., evaluating && earlier) or miscompute bitwise results. None match the correct parsing sequence defined by the C standard.
Common Pitfalls:
Believing logical && outranks bitwise |, or forgetting that nonzero integers are “true” for logical operators so 12 && 12 is 1, not 12.
Final Answer:
12, 1, 12
Discussion & Comments