C++ Programming :: Templates

Home > Technical Aptitude > C++ Programming > Templates > General Questions

NA
SHSTTON
4
Solv. Corr.
3
Solv. In. Corr.
7
Attempted
0 M:13 S
Avg. Time

1 / 33

Choose the correct option.

Template support


Ageneric programming

Bobject-oriented programming

Cprocedural programming

Dstructured programming

Answer: Option A

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
3
Solv. Corr.
3
Solv. In. Corr.
6
Attempted
0 M:0 S
Avg. Time

2 / 33

Choose the correct option.

Which of the following can be passed to function template as an argument?


AUser-defined data types

BPrimitive data type

CStruct type

DAll of these

Answer: Option D

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
4
Solv. Corr.
1
Solv. In. Corr.
5
Attempted
0 M:0 S
Avg. Time

3 / 33

Choose the correct option.

The desired type is added to a specific template class instantiation by placing the type's name


Abetween angle brackets

Bin parentheses

Con a line by itself

Dimmediately prior to the class name.

Answer: Option A

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
2
Solv. Corr.
4
Solv. In. Corr.
6
Attempted
0 M:0 S
Avg. Time

4 / 33

Choose the correct option.

Function template can be overloaded with


Aother function of its name

Bother template function of same name

Cboth (a) and (b)

Dcan't be overloaded.

Answer: Option C

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
0
Solv. Corr.
5
Solv. In. Corr.
5
Attempted
0 M:0 S
Avg. Time

5 / 33

Choose the correct option.

A class template can declare


Aglobal data members

Bconstant data members

Cstatic data members

Dboth (b) and (c)

Answer: Option C

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
3
Solv. Corr.
2
Solv. In. Corr.
5
Attempted
0 M:0 S
Avg. Time

6 / 33

Choose the correct option.

The arguments of class template are of


Acharacter string type

Bstatic class member

Ctemplate type

Dall of these

Answer: Option D

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
2
Solv. Corr.
3
Solv. In. Corr.
5
Attempted
0 M:0 S
Avg. Time

7 / 33

What is the output of the below C++ program?
#include < iostream >
#include < string >
using namespace std;
template < typename T >
void print_mydata(T output)
{
cout << output << endl;
}
int main()
{
double d = 5.5;
string s("Hello World");
print_mydata( d );
print_mydata( s );
return 0;
}

A5.5

BHello World

CHello

Dnone of the mentioned

Answer: Option A

Explanation:

Passing the value to template and printig it in template.

Workspace

NA
SHSTTON
2
Solv. Corr.
2
Solv. In. Corr.
4
Attempted
0 M:0 S
Avg. Time

8 / 33

Choose the correct option.

How many types of templates are there in c++?


A1

B2

C3

D4

Answer: Option B

Explanation:

function template
class template

Workspace

NA
SHSTTON
4
Solv. Corr.
0
Solv. In. Corr.
4
Attempted
0 M:0 S
Avg. Time

9 / 33

Choose the correct option.

What is a template?


AA template is a formula for creating a generic class

BA template is used to manipulate the class

CA template is used for creating the attributes

Dnone of the mentioned

Answer: Option A

Explanation:

A template is a formula for creating a generic class

Workspace

NA
SHSTTON
3
Solv. Corr.
1
Solv. In. Corr.
4
Attempted
0 M:0 S
Avg. Time

10 / 33

Choose the correct option.

What is meant by template parameter?


AIt can be used to pass a type as argument

BIt can be used to evaluate a type.

CIt can of no return type

DNone of the mentioned

Answer: Option A

Explanation:

A template parameter is a special kind of parameter that can be used to pass a type as argument.

Workspace