ProgrammingVery hardInfosys DSE · Wipro Elite

What is printed? (C++17; assume <iostream>, <string>, <vector> and using namespace std)

What is printed? (C++17; assume <iostream>, <string>, <vector> and using namespace std)
template <class T> void f(T) { cout << "T"; }
void f(int) { cout << "I"; }
int main() { f(1); f('a'); f(1.0); }
  1. A. III
  2. B. ITT
  3. C. ITI
  4. D. TTT

Correct answer: B. ITT

f(1) ties on exact match so the non-template wins; for 'a' and 1.0 the template deduces an exact match, beating the promotion/conversion needed for f(int).

More OOP with C++ and Java questions

Exams that ask this topic