Search Header Logo

C++ Template Quiz

Authored by Suraj Singh

Other

Professional Development

Used 1+ times

C++ Template Quiz
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

8 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

What is a template in C++?

A blueprint for creating classes and functions

A way to include files

A method to allocate memory

A type of pointer

2.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Which keyword is used to define a template in C++?

template

class

typename

include

3.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

What is the correct syntax to declare a template class?

template <typename T> class ClassName { ... };

class template <T> { ... };

class ClassName { template <T> ... };

template class <typename T> ClassName { ... };

4.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Which of the following correctly declares a friend function inside a template class?

friend void functionName();

friend void ClassName::functionName();

friend class ClassName;

friend void functionName(ClassName<T>&)

5.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Why are friend functions used in C++?

To access private and protected members of a class

To create multiple instances of a class

To initialize class members

To overload operators

6.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Can a template class have more than one type parameter?

Yes, by using multiple typename or class keywords

No, only one type parameter is allowed

Yes, but only with a specific compiler flag

No, it’s not possible in C++

7.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Which of the following is a correct example of instantiating a template class?

ClassName<int> obj;

ClassName<int> obj();

template <int> ClassName obj;

ClassName<obj> int;

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?