Difficulty: Medium
Correct Answer: The program will print the output x = 180.
Explanation:
Introduction / Context:
This question examines overload resolution when two viable overloads accept parameters that can be formed from the same call via standard conversions, and where defaults supply missing arguments. It highlights that exact matches and promotions out-rank other standard conversions.
Given Data / Assumptions:
CuriousTabFunction(10 * 1.0, int(56.0))
i.e., arguments are double
and int
.(int, float, char = 'A')
and (float, int, char = 'Z')
.(char, char, char)
is not viable for the given types without narrowing conversions to char.
Concept / Approach:
For the first parameter, both candidates require converting a double
(to int
or to float
). For the second parameter, the (float, int, char)
overload has an exact match for the provided int
, while the (int, float, char)
overload requires converting int
to float
. Therefore, the chosen overload is CuriousTabFunction(float, int, char)
with zz
defaulting to 'Z'
(ASCII 90).
Step-by-Step Solution:
(float, int, char)
.Compute x = zz + zz = 90 + 90 = 180
.The function prints " x = 180"
.
Verification / Alternative check:
Force the other overload with an explicit cast: obj.CuriousTabFunction(int(10.0), float(56.0))
and the output will reflect x = 10 + 56
.
Why Other Options Are Wrong:
Common Pitfalls:
Overlooking that the second parameter is an exact match for int
in the float-int-char overload, which tips the ranking.
Final Answer:
The program will print the output x = 180.
Discussion & Comments