Home » C++ Programming » Templates » Question
  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    template<typename T>
    void loopIt(T p)
    {
    int n = 2;
    T value[n];
    for (int k=0; k < n; k++)
    {
    value[k] = p++;
    cout << value[k] << endl;
    }
    };
    int main()
    {
    float q = 4.25;
    loopIt(q);
    }
    1. 10.5
      11.5
    2. 10.5
    3. 11.5
    4. 11.5
      10.5
    5. None of these
Correct Option: A

In this program, We are using the non-type template parameter to increment the value in the function template.



Your comments will be displayed only after manual approval.