Understanding C++ Default Arguments in Function Calls
The function definition is $Void xyz (int a = 0, int b, int c = 0)$.
Key C++ rules for default arguments:
- Parameters with default values must appear at the end of the parameter list. (Note: The provided signature technically violates this rule as $b$ is between $a$ and $c$, but we proceed based on the question's premise).
- When calling a function, arguments are matched from left to right.
- A parameter without a default value must always be provided an argument during the function call.
- If you skip an argument for a parameter with a default value, all subsequent parameters must also be skipped (and thus rely on their default values or must also have defaults).
Analyzing Function Calls for Legality
Let's analyze each call based on the rules, considering the parameter $b$ requires a value:
Call (a): $xyz( );$
- This call provides zero arguments.
- The parameter $b$ does not have a default value and is not provided.
- Result: Illegal
Call (b): $xyz (h, h) ;$
- This call provides two arguments.
- The first argument $h$ is assigned to $a$.
- The second argument $h$ is assigned to $b$.
- The parameter $c$ is omitted and takes its default value $0$.
- Since $b$ receives a value, this call is valid.
- Result: Legal
Call (c): $xyz (h);$
- This call provides one argument.
- The argument $h$ is assigned to $a$.
- The parameter $b$ is omitted. Since $b$ lacks a default value, it must be supplied.
- Result: Illegal
Call (d): $xyz (g, g);$
- This call provides two arguments.
- The first argument $g$ is assigned to $a$.
- The second argument $g$ is assigned to $b$.
- The parameter $c$ is omitted and takes its default value $0$.
- Since $b$ receives a value, this call is valid.
- Result: Legal
Conclusion on Call Legality
Based on the analysis:
- Calls $xyz (h, h)$ and $xyz (g, g)$ are legal because the mandatory parameter $b$ receives a value.
- Calls $xyz( )$ and $xyz (h)$ are illegal because the mandatory parameter $b$ does not receive a value.
Therefore, the calls $(b)$ and $(d)$ are the ones considered valid (correct) in this context.