Templates

26.Which of the following syntax is used to create a template alias?
  • A. using T = template<int T>
  • B. using T = Template<int>
  • C. template <typename T> using T = typename
  • D. using T = std::vector<int>;

using T = std::vector<int>;

using T = std::vector<int>;

27.Can template functions be called with the same name but different argument types?
  • A. Yes, this is allowed
  • B. No, this results in ambiguity
  • C. Template functions cannot be called with different argument types
  • D. It requires function overloading

Yes, this is allowed

Yes, this is allowed

28.What is the output of this code?
template T add(T a, T b) { return a + b; } int main() { std::cout << add(1, 2.5) << std::endl; }
  • A. 3.5
  • B. Compilation error due to type mismatch
  • C. 3
  • D. 2.5

Compilation error due to type mismatch

Compilation error due to type mismatch

29.How do you define a class template with multiple parameters in C++?
  • A. template <class T, class U> class MyClass {};
  • B. template <typename T> class MyClass<T, int> {};
  • C. template <T, U> class MyClass {};
  • D. template <class T class U> class MyClass {};

template <class T, class U> class MyClass {};

template <class T, class U> class MyClass {};

30.What is template metaprogramming in C++?
  • A. Writing functions that only work with specific types
  • B. A technique for creating a more complex code structure using templates
  • C. A way to manipulate types and values at compile-time
  • D. Writing multiple classes based on a template

A way to manipulate types and values at compile-time

A way to manipulate types and values at compile-time