Question discussion

What is the output of the following C++ program?#include using namespace std; template T mx(T a, T b) { return a > b ? a : b; } int main()…

964Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following C++ program?

#include <iostream>
using namespace std;
template <class T> T mx(T a, T b) { return a > b ? a : b; }
int main() {
    cout << mx(3, 7) << mx('a', 'Z') << mx(2.5, 1.5);
}
  • A7Z2.5
  • B7a1.5
  • C3a2.5
  • D7a2.5
Correct answer: D

Explanation

mx(3,7) = 7; for chars 'a' (97) > 'Z' (90), so 'a'; mx(2.5, 1.5) = 2.5.

Discussion 0

Nobody has replied yet. Start the discussion!