Home » C++ Programming » Templates » Question
  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    template <typename T, typename U>
    void squareAndPrint(T p, U q)
    {
    cout << p << p * p << endl;
    cout << q << " " << q * q << endl;
    };
    int main()
    {
    int kk = 3;
    float LL = 3.12;
    squareAndPrint<int, float>(kk, LL);
    }
    1. 39
      3.12 9.7344
    2. 3.12
      9.7344 39
    3. 3.12 9.7344
      39
    4. Compilation Error
    5. None of these
Correct Option: A

In this multiple templated types, We are passing two values of different types and producing the result.



Your comments will be displayed only after manual approval.