Home / CSE MCQs / C++ - MCQs :: Templates - C++

CSE MCQs :: C++ - MCQs

  1. What is a template?
  2. A.
    A template is a formula for creating a generic class
    B.
    A template is used to manipulate the class
    C.
    A template is used for creating the attributes
    D.
    none of the mentioned

    View Answer

    Workspace

    Discuss Discuss in Forum


  3. Pick out the correct statement about string template?
  4. A.
    It is used to replace a string.
    B.
    It is used to replace a string with another string at runtime.
    C.
    It is used to delete a string.
    D.
    none of the mentioned

    View Answer

    Workspace

    Discuss Discuss in Forum


  5. How to declare a template?
  6. A.
    tem
    B.
    temp
    C.
    template < >
    D.
    none of the mentioned

    View Answer

    Workspace

    Discuss Discuss in Forum


  7. What is the output of this program?

    #include < iostream >
    #include < string >
    using namespace std;
    template < typename T >
    void print_mydata(T output)
    {
    cout << output << endl;
    }
    int main()
    {
    double d = 5.5;
    string s("Hello World");
    print_mydata( d );
    print_mydata( s );
    return 0;
    }
  8. A.

    5.5

     Hello World

    B.
    5.5
    C.
    Hello World
    D.
    none of the mentioned

    View Answer

    Workspace

    Discuss Discuss in Forum


  9. How many types of templates are there in c++?
  10. A.
    1
    B.
    2
    C.
    3
    D.
    4

    View Answer

    Workspace

    Discuss Discuss in Forum


  11. Which are done by compiler for templates?
  12. A.
    type-safe
    B.
    portability
    C.
    code elimination
    D.
    all of the mentioned

    View Answer

    Workspace

    Discuss Discuss in Forum


  13. What may be the name of the parameter that the template should take?
  14. A.
    same as template
    B.
    same as class
    C.
    same as function
    D.
    none of the mentioned

    View Answer

    Workspace

    Discuss Discuss in Forum


  15. How many parameters are legal for non-type template?
  16. A.
    1
    B.
    2
    C.
    3
    D.
    4

    View Answer

    Workspace

    Discuss Discuss in Forum


  17. What is a function template?
  18. A.
    creating a function without having to specify the exact type.
    B.
    creating a function with having a exact type.
    C.
    both a & b
    D.
    none of the mentioned

    View Answer

    Workspace

    Discuss Discuss in Forum


  19. Which is used to describe the function using placeholder types?
  20. A.
    template parameters
    B.
    template type parameters
    C.
    template type
    D.
    none of the mentioned

    View Answer

    Workspace

    Discuss Discuss in Forum