Templates


  1. Pick out the correct statement about string template.











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    Every string template is used to replace the string with another string at runtime.


  1. What is a template?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    A template is a formula for creating a generic class



  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    template <class T>
    class Example
    {
    public:
    void putPri();
    static T ipub;
    private:
    static T ipri;
    };
    template <class T>
    void Example<T>::putPri()
    {
    cout << ipri++ << endl;
    }
    template <class T> T Example<T>::ipub = 1.5;
    template <class T> T Example<T>::ipri = 2.5;
    int main()
    {
    Example<int> a;
    Example<float> b;
    a.putPri();
    cout << a.ipub << endl;
    b.putPri();
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    In this program, We are passing the value of specified type and printing it by specialization.


  1. How many kinds of entities are directly parameterized in c++?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    C++ allows us to parameterize directly three kinds of entities through templates: types, constants, and templates.



  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    class BaseClass
    {
    public:
    BaseClass( )
    {
    cout << "I ";
    }
    ~BaseClass ( )
    {
    cout << " Mania";
    }
    };
    class DerivedClass : public BaseClass
    {
    public:
    DerivedClass ( )
    {
    cout << "Love ";
    }
    ~DerivedClass ( )
    {
    cout << "Interview";
    }
    };
    int main( )
    {
    DerivedClass x;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: E

    In this program, We are printing the order of execution of constructor and destructor in the class.