Chapter 22 – C How to Program 6e Multiple Choice Test Bank
Download file with the answers
Chapter 22 - C How to Program 6e Multiple Choice Test Bank
1 file(s) 138.94 KB
Not a member!
Create a FREE account here to get access and download this file with answers
Chapter 22: Templates
Section 22.1 Introduction
22.1 Q1: The relationship between function templates and function-template specializations is most similar to the relationship between:
a. Classes and objects.
b. Classes and functions.
c. Functions and return types.
d. Headers and source files.
Section 22.2 Function Templates
22.2 Q1: A difference between function-template specializations and overloaded functions is that:
a. Function-template specializations are generated by the compiler, not the programmer.
b. Function-template specializations cannot accept user-defined types.
c. Function-template specializations do not perform identical operations on each data type.
d. Overloaded functions usually do not perform similar operations on each data type.
22.2 Q2: Function-template specializations:
a. Are identical to macros.
b. Are generated at compile time.
c. Have a maximum allowed number of type parameters.
d. Are not more concise than the equivalent set of overloaded functions.
Section 22.3 Overloading Function Templates
22.3 Q1: A function template can be overloaded by:
a. Using other function templates with the same function name and parameters.
b. Using non-template functions with the same name and different parameters.
c. Using non-template functions with a different name but the same parameters.
d. Using other function templates with a different name but the same parameters.
22.3 Q2: Assuming that all four of the following functions are defined, which one will be called by the function call square( 23.4 )?
a. template< typename T >
T square( T num )
b. template< typename T1, typename T2 >
T1 square( T1 num1, T2 num2 )
c. int square( int num )
d. double square( double num )
Section 22.4 Class Templates
22.4 Q1: Class templates:
a. May include the statement template< typename Type > anywhere.
b. Must put template< typename Type > before the class definition.
c. Must include template< typename Type > inside the class definition.
d. Have the option of including the optional statement template< typename Type >.
22.4 Q2: For a class template, the binary scope resolution operator (::) is needed:
a. Only in the definitions of the member functions defined outside the class.
b. Both in the prototype and definition of a member function.
c. Only if multiple class-template specializations will be created from this class template.
d. In neither the definition nor prototype of member functions.
22.4 Q3: Function templates:
a. Can include objects of template classes as parameters.
b. Must have return type T.
c. Do not need a separate template< typename type > statement if they take objects from a template class as a parameter.
d. Do not need a separate template< typename type > statement.
Section 22.5 Nontype Parameters and Default Types for Class Templates
22.5 Q1: Nontype parameters are:
a. Unable to have default arguments.
b. Specified before the angle-bracket-enclosed type-parameter list.
c. const.
d. Required for class templates.
22.5 Q2: Default type parameters are allowed only:
a. If the class template also has nontype parameters.
b. If the class template does not have any nontype parameters.
c. If the class is used as a container class.
d. As the rightmost (trailing) parameters in a template’s type-parameter list.
Leave a reply