Test Series - cpp

Test Number 47/102

Q: What is the syntax of class template?
A. template class declaration
B. Template class declaration
C. temp class declaration
D. Temp class declaration
Solution: Syntax involves template keyword followed by list of parameters in angular brackets and then class declaration. As follows template  class declaration;
Q: How the template class is different from the normal class?
A. Template class generate objects of classes based on the template type
B. Template class saves system memory
C. Template class helps in making genetic classes
D. All of the mentioned
Solution: Size of the object of template class varies depending on the type of template parameter passed to the class. Due to which each object occupies different memories on system hence saving extra memories. Template class also helps in making generic classes.
Q: How many template parameters are allowed in template classes?
A. 1
B. 2
C. 3
D. one or more
Solution: Just like normal parameters we can pass more than one or more template parameters to a template class.
Q: What is meant by the template parameter?
A. It can be used to pass a type as an argument
B. It can be used to evaluate a type
C. It can of no return type
D. It can be used to delete a type
Solution: A template parameter is a special kind of parameter that can be used to pass a type as argument.
Q: Which keyword can be used in template?
A. class
B. typename
C. both class & typename
D. function
Solution: Both keywords can be used as shown below:
template  function declaration;
template  function declaration;
Q: What is the validity of template parameters?
A. inside that block only
B. inside the class
C. whole program
D. inside the main class
Solution: Template parameters are valid inside a block only i.e. they have block scope.
Q: Why we use :: template-template parameter?
A. binding
B. rebinding
C. both binding & rebinding
D. reusing
Solution: It is used to adapt a policy into binary ones.
Q: Which parameter is legal for non-type template?
A. pointer to member
B. object
C. class
D. baseclass
Solution: The following are legal for non-type template parameters:integral or enumeration type, Pointer to object or pointer to function, Reference to object or reference to function, Pointer to member.
Q: Which of the things does not require instantiation?
A. functions
B. non virtual member function
C. member class
D. all of the mentioned
Solution: The compiler does not generate definitions for functions, non virtual member functions, class or member class because it does not require instantiation.

You Have Score    /9