C++ | Templates | Question 3

#include <iostream>
using namespace std;

template <typename T>
T max(T x, T y)
{
    return (x > y)? x : y;
}
int main()
{
    cout << max(3, 7) << std::endl;
    cout << max(3.0, 7.0) << std::endl;
    cout << max(3, 7.0) << std::endl;
    return 0;
}

(A)

7
7.0
7.0

(B) Compiler Error in all cout statements as data type is not specified.
(C) Compiler Error in last cout statement as call to max is ambiguous.
(D) None of the above


Answer: (C)

Explanation:

Quiz of this Question






Practice Tags :

Recommended Posts:



0 Average Difficulty : 0/5.0
No votes yet.