Difficulty: Easy
Correct Answer: 30
Explanation:
Introduction / Context:
This question verifies that default arguments are associated with the callee declaration, not with pointers, and that they are applied when omitted at the call. The function pointer invokes Note, which calls Look(x) with only one explicit argument, letting the default fill the second parameter.
Given Data / Assumptions:
Look is declared as int Look(int = 10, int = 20);Note(int x) calls Look(x); thus y defaults to 20.x + y % 20 means x + (y % 20).
Concept / Approach:
When Look is called with a single argument, the default y = 20 is used. Because y % 20 = 0, the return becomes x + 0 = x. The pointer indirection (*ptr)(30) simply routes to Note(30) and does not change default-argument behavior.
Step-by-Step Solution:
1) (*ptr)(30) ⇒ calls Note(30). 2) Note calls Look(30) ⇒ y defaults to 20. 3) Compute Look: 30 + (20 % 20) = 30 + 0 = 30. 4) Note prints 30.
Verification / Alternative check:
If Note were cout << Look(x, 5), the result would be x + (5 % 20) = x + 5.
Why Other Options Are Wrong:
10/20/40 assume different argument counts or precedence; compilation succeeds as signatures are consistent.
Common Pitfalls:
Assuming defaults are tied to function pointers or misreading the modulo precedence.
Final Answer:
30
Discussion & Comments