Difficulty: Easy
Correct Answer: 12, 12
Explanation:
Introduction / Context:
This problem examines the C comma operator inside a return statement. The comma operator evaluates its left operand, discards the result, then evaluates and yields the right operand. Understanding this behavior explains the function’s return value and the program’s output.
Given Data / Assumptions:
Concept / Approach:
For the expression (kk, ll), C guarantees left-to-right evaluation with the result being the value of the rightmost expression. Thus, the function returns the value of ll, which is 12.
Step-by-Step Solution:
Compute kk = 3 + 4 = 7.Compute ll = 3 * 4 = 12.Evaluate (kk, ll): first kk (discard), then ll → result 12.So addmult returns 12 each call.k = 12 and l = 12; printf prints "12, 12".
Verification / Alternative check:
Replace return (kk, ll) with return ll; Behavior is the same, confirming the result.
Why Other Options Are Wrong:
"7, 7" or mixed values assume kk is returned; that contradicts the comma operator. No compile error occurs; the comma operator is valid.
Common Pitfalls:
Confusing the comma operator with the comma that separates function arguments. Inside an expression, it has defined evaluation and result rules.
Final Answer:
12, 12
Discussion & Comments