Difficulty: Medium
Correct Answer: The program will print the output 8.
Explanation:
Introduction / Context:
This item examines overload resolution when one overload exactly matches the argument list and another is also viable by supplying a default argument. The C++ rules select the best viable function, favoring an exact arity match over one that relies on defaults.
Given Data / Assumptions:
Concept / Approach:
Overload resolution prefers the function that requires no default arguments and exactly matches the number and types of the provided parameters. Therefore CuriousTabTest(int,int) is selected, computing 2 * 4 = 8.
Step-by-Step Solution:
Verification / Alternative check:
If the call were CuriousTabTest(2,4,5), the three-parameter version would be chosen and print 40. Removing the two-parameter overload would also yield 40 due to the default.
Why Other Options Are Wrong:
Common Pitfalls:
Thinking the presence of a defaulted parameter forces selection of that overload; in reality, defaults only make a function viable, not necessarily the best match.
Final Answer:
The program will print the output 8.
Discussion & Comments