Difficulty: Easy
Correct Answer: The program will print the output 12 98 a.
Explanation:
Introduction / Context:
This question checks how default arguments combine with implicit conversions when actual arguments do not match the declared parameter types exactly. It also confirms that omitted trailing parameters receive their defaults in a nested class method call context.
Given Data / Assumptions:
Display(int x, float y = 97.50, char ch = 'a')
.Display(12, 'b')
(second argument is a char literal).
Concept / Approach:
The second parameter expects float
. Passing 'b'
(ASCII 98) converts to an integral value 98 and then to float
as 98.0f
. The third parameter is omitted, so it takes its default 'a'
. Thus, the stream prints the integer-looking representation of the float (implementation typically shows "98") and the char a
.
Step-by-Step Solution:
Verification / Alternative check:
If the call were Display(12)
, output would be "12 97.5 a". If it were Display(12, 98.0f, 'b')
, you would see "12 98 b".
Why Other Options Are Wrong:
Common Pitfalls:
Expecting the literal 'b'
to bind to char ch
; parameters are positional, so it binds to the second (float
) parameter.
Final Answer:
The program will print the output 12 98 a.
Discussion & Comments