What is the output of the following C++ program?
#include <iostream>
using namespace std;
void print(int x) {
cout << "int";
}
void print(double x) {
cout << "double";
}
int main() {
print(5);
return 0;
}
Options
-
A.
int
-
B.
double
-
C.
Compilation error because print is overloaded
-
D.
More than one of the above
-
E.
None of the above
Correct Answer (Detailed Explanation is Below)
A.
int
Detailed Explanation
Correct Answer: Option AExplanation:The literal 5 has type int, so the overload print(int) is an exact match. The compiler resolves the overloaded function call at compile time and prints
int.