C++ Templates - placement practice test

C++ Templates - placement practice test


1. _________________are used for generic programming

a. Inheritance
b. Virtual Functions
c. templates
d. None of these
View Answer / Hide Answer

ANSWER: c. templates




2. Which of the following best defines the syntax for template function ?

a. template return_type Function_Name(Parameters)
b. template
return_type Function_Name(Parameters)
c. both a and b
d. None of these
View Answer / Hide Answer

ANSWER: c. both a and b




3. Which one is suitable syntax for function template?

a. template< class T> return_type Function_Name(parameters)
b. template< typename T> return_type Function_Name(parameters)
c. both and b
d. None of these
View Answer / Hide Answer

ANSWER: c. both and b
Explanation: Both class and typename keywords can be used alternatively for specifying a generic type in a template.




4. Can we have overloading of the function templates?

a. Yes
b. No
View Answer / Hide Answer

ANSWER: a. Yes




5. In a program, If there exists a function template with two parameters and normal function say void add(int , int), so add(3,4) will_____________________

a. Invoke function template body as it is generic one
b. Invokes normal function as it exactly matches with its prototype
c. Not be called and Compiler issues warning
d. Not be called and Compiler issues ambiguity in calling add()
View Answer / Hide Answer

ANSWER: b. Invokes normal function as it exactly matches with its prototype



Post your comment