Difficulty: Easy
Correct Answer: Both B and C are incorrect.
Explanation:
Introduction / Context:
Default parameters in C++ must be supplied from the rightmost side leftward. Once a parameter has a default, all parameters to its right must also have defaults. Violating this rule results in declarations that cannot be called unambiguously because you would need to “skip” a middle parameter at the call site, which is not allowed.
Given Data / Assumptions:
Concept / Approach:
Declaration A is valid: defaults are at the end (b and c), so callers may pass 1, 2, or 3 arguments. Declaration B is invalid because it gives a default to the first parameter but not to the second; callers would have to omit the first but still supply the second, which C++ cannot express. Declaration C is also invalid because a non-defaulted parameter b
appears between defaulted parameters; callers could not omit the middle argument while taking the third’s default. Therefore, the best summary is that B and C are incorrect.
Step-by-Step Solution:
Verification / Alternative check:
Attempt to compile B and C: compilers emit errors. A compiles and is callable as Sum(1), Sum(1,2), and Sum(1,2,3).
Why Other Options Are Wrong:
“All are correct” is wrong because B and C break the rule.
Any single choice misses that both B and C fail.
Common Pitfalls:
Final Answer:
Both B and C are incorrect.
Discussion & Comments