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 val[n];
    for (int k=0; k < n; k++)
    {
    val[k] = p++;
    cout << val[k] << endl;
    }
    };
    int main()
    {
    float q = 4.25;
    loopIt(q);
    }
    1. 5.25
    2. 4.25
      5.25
    3. 4.25
    4. 5.25
      4.25
    5. None of these
Correct Option: B

In this program, We are using the for loop to increment the value by 1 in the function template.



Your comments will be displayed only after manual approval.