Question 1
What is the main purpose of function templates in C++?
To make functions execute faster
To store multiple function definitions in one place
To create generic functions that work with multiple data types
To restrict a function to only one data type
Question 2
Which keyword is used to define a template in C++?
template
typename only
generic
template_function
Question 3
Consider the following code:
#include
using namespace std;
template <typename T>
T add(T a, T b) {
return a + b;
}
int main() {
cout << add(5, 10);
}
What will be the output?
Compilation Error
5 10
15
Undefined Behaviour
Question 4
Which is the correct syntax for template specialization for int type?
template <> int func<int>(int a) { ... }
template <> int func<int>(int a) { ... }
template <> int func(int a) { ... }
specialize template int func(int a) { ... }
Question 5
Which of the following is TRUE about variadic function templates?
They can accept only integers
They are available since C++98
They can accept a variable number of template arguments
They require all arguments to be the same type
Question 6
What is the base case in a variadic function template recursion?
When the compiler finds no template arguments left
When there are two arguments left
When all arguments are of the same type
 When the last argument is nullptr
There are 6 questions to complete.