Difficulty: Easy
Correct Answer: a = 20 b = 30
Explanation:
Introduction / Context:
This is a straightforward default-argument question. The function MyFunction
supplies a default only for its second parameter, but the call provides both arguments explicitly, so the default is not used.
Given Data / Assumptions:
void MyFunction(int a, int b = 40)
.MyFunction(20, 30)
.
Concept / Approach:
Default arguments are only consulted for parameters omitted at the call. Any explicitly supplied argument replaces the default entirely. The stream concatenates literal text with values, so the line printed reflects the exact bound values.
Step-by-Step Solution:
1) Bind a = 20. 2) Bind b = 30 (explicit at call site). 3) Function executes and prints “ a = 20 b = 30”.
Verification / Alternative check:
If the call were MyFunction(20)
, the output would be “ a = 20 b = 40”.
Why Other Options Are Wrong:
“a = 20 b = 40” incorrectly applies the default; “Garbage” and “Compilation fails” have no basis because types match and the program is valid.
Common Pitfalls:
Thinking defaults are always printed regardless of arguments; forgetting that the literal spaces are as coded.
Final Answer:
a = 20 b = 30
Discussion & Comments