-
What is the output of this program?
#include <iostream>
using namespace std;
template <class T>
inline T square(T n1)
{
T Output;
Output = n1 * n1;
return Output;
};
template <>
string square<string>(string Str)
{
return (Str + Str);
};
int main()
{
int k = 4, kk;
string bb("B");
kk = square<int>(k);
cout << k << ": " << kk;
cout << square<string>(bb) << ":" << endl;
}
-
- 4:
- 4: 16BB:
- 16BB:
- 16BB: 4:
- None of these
Correct Option: B
Template specialization is used when a different and specific implementation is to be used for a specific data type. In this program, We are using integer and character.