Home » C++ Programming » Templates » Question
  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    template <class T>
    inline T square(T p)
    {
    T result;
    result = p * p;
    return result;
    };
    template <>
    string square<string>(string str)
    {
    return (str+str);
    };
    int main()
    {
    int k = 4, kk;
    string bb("A");
    kk = square<int>(k);
    cout << k << kk;
    cout << square<string>(bb) << endl;
    }
    1. 164AA
    2. AA416
    3. 416AA
    4. All of above
    5. None of these
Correct Option: C

In this program, We are using two template to calculate the square and to find the addition.



Your comments will be displayed only after manual approval.