Difficulty: Easy
Correct Answer: We can provide a default value to a particular argument in the middle of an argument list.
Explanation:
Introduction / Context:
Default arguments in C++ allow you to omit trailing parameters at call sites, improving API ergonomics. However, the language enforces strict placement and declaration rules so that overload resolution remains unambiguous and readable. This question asks you to identify the statement that contradicts those rules.
Given Data / Assumptions:
Concept / Approach:
C++ requires that once a parameter is given a default value, all parameters to its right must also have defaults. In other words, defaults must be trailing in the parameter list. You therefore cannot “skip” and default just a middle parameter while leaving a later parameter non-defaulted. Doing so would make the call syntax ambiguous and break predictable argument binding.
Step-by-Step Solution:
1) Consider f(a, b = 10, c). This is ill-formed because c has no default after b does.2) A correct arrangement is f(a, b, c = 42) or f(a, b = 10, c = 42).3) Type checking of the default expression occurs at the declaration; its evaluation happens each time the default is actually used at a call site.4) Hence, the statement claiming you can default “a middle” parameter while leaving later ones undecided is the incorrect one.
Verification / Alternative check:
Try compiling a function with a middle default and a non-default trailing parameter. Compilers reject it with diagnostics indicating that a parameter with no default follows a parameter with a default.
Why Other Options Are Wrong:
Type-checked-at-declaration and evaluated-at-call is correct per the language model.“We cannot provide a default value in the middle” is a correct statement of the rule.Usefulness claim is correct: defaults simplify common-case calls.
Common Pitfalls:
Repeating default values in multiple declarations (ODR hazards) or attempting to default only some non-trailing parameters, causing compile errors.
Final Answer:
We can provide a default value to a particular argument in the middle of an argument list.
Discussion & Comments