Difficulty: Easy
Correct Answer: z=1
Explanation:
Introduction / Context:
Logical operators in C convert relational results to either 0 (false) or 1 (true). This simple example reinforces that comparisons yield 0 or 1 and that the logical OR operator short-circuits once a true operand is found.
Given Data / Assumptions:
Concept / Approach:
Evaluate the left comparison first: x != 4 is true (12 is not 4), which yields 1. Since || short-circuits, the right side does not affect the final result; z is set to 1. The printf prints z as “1”.
Step-by-Step Solution:
Verification / Alternative check:
Replace y with any value; as long as x != 4 remains true, z stays 1. Conversely, set x to 4 and y to 2 to see z remain 1 due to the right operand.
Why Other Options Are Wrong:
Common Pitfalls:
Thinking relational operators return operands themselves; in C99+ the result is guaranteed 0 or 1 for these logical forms.
Final Answer:
z=1.
Discussion & Comments