Function Templates
Class Templates
STL (Standard Template Library)
100

No, it is just common practice to use T. It is a shortcut for type.

Do we have to use T for template variables?

100

A blueprint for creating classes with any data type.

What is a class template?

100

Standard Template Library

What does STL stand for?

200

Code reusability for any data type.

What is the main benefit of using function templates in C++?

200

template <class T1, class T2>

class MyClass {...};

How do you define a class template with two data types?

200

Generic algorithms (e.g., sort, find)

What type of algorithms are used with STL containers?

300

template<typename T>

void swap(T &a, T &b);

How do you define a simple function template that swaps two variables?

300

At compile time when the template is used with a specific data type.

When is the class template instantiated?

300

A type of pointer used to access elements in a container.

What is an iterator in STL?

400

A template is C++'s version of a generic (a common term for the same concept as a template but in other languages), which allows code to work with any data type.

What is the difference between a generic and a template?


400

Yes, even the implementation must be in the header file for templated functions.

Does everything have to be in the header file for templated functions?

400

map

Which STL container allows access using key-value pairs?


500

By using the template parameters (e.g., T1, T2) inside the class definition.

How does a template class handle multiple different types internally?