Home » C++ Programming » Templates » Question
  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    template <typename T = float, int count = 3>
    T Multiply(T num1)
    {
    for(int kk = 0; kk < count; kk++)
    {
    num1 = num1 * num1;
    }
    return num1;
    };
    int main()
    {
    float num2 = 1.25;
    cout << num2 << " " << Multiply<>(num2) << endl;
    }
    1. 1.25
    2. 5.96046
    3. 1.25 5.96046
    4. 5.96046 1.25
    5. None of these
Correct Option: D

In this program, We specify the type in the template function. We need to compile this program by adding -std=c++0x.



Your comments will be displayed only after manual approval.