Home » C++ Programming » Templates » Question
  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    template<class T = float, int k = 5> class N
    {
    public:
    N();
    int value;
    };
    template<> class N<>
    {
    public: N();
    };
    template<> class N<double, 10>
    {
    public: N();
    };
    template<class T, int k> N<T, k>::N() : value(k)
    {
    cout << value;
    }
    N<>::N()
    {
    cout << " Out of ";
    }
    N<double, 10>::N()
    {
    cout << "10" << endl;
    }
    int main()
    {
    N<int, 8> x;
    N<> y;
    N<double, 10> z;
    }
    1. 10 out of 8
    2. 8
    3. 10
    4. 8 out of 10
    5. None of these
Correct Option: D

In this program, We are defining three templates and specializing it and passing the values to it and printing it.



Your comments will be displayed only after manual approval.