Sail E0 Webinar

MCQs

Total Questions : 10
Question 1.

What is other name of full specialization?


  1.    explicit specialization
  2.    implicit specialization
  3.    function overloading template
  4.    None of the mentioned
 Discuss Question
Answer: Option A. -> explicit specialization

None


Question 2.

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


  1.    1
  2.    2
  3.    3
  4.    4
 Discuss Question
Answer: Option B. -> 2

There are two types specialization. They are full specialization and partial specialization.


Question 3.


What is the output of this program?


1.
#include
2.
using namespace std;
3.
template class A
4.
{
5.
public:
6.
A();
7.
int value;
8.
};
9.
template class A
10.
{
11.
public: A();
12.
};
13.
template class A
14.
{
15.
public: A();
16.
};
17.
template A::A() : value(i)
18.
{
19.
cout
  1.    6
  2.    10
  3.    6default10
  4.    None of the mentioned
 Discuss Question
Answer: Option C. -> 6default10

In this program, We are defining three templates and specializing it and passing the values to 

it and printing it.
Output:
$ g++ spec5.cpp
$ a.out
6default10


Question 4.


What is the output of this program?


1.
#include
2.
#include
3.
#include
4.
using namespace std;
5.
template
6.
type MyMax(const type Var1, const type Var2)
7.
{
8.
cout
  1.    template
  2.    class
  3.    no specialization
  4.    None of the mentioned
 Discuss Question
Answer: Option A. -> template

In this program, We are computing the result in the specalized block of the program.
Output:
$ g++ spec3.cpp
$ a.out
template


Question 5.


What is the output of this program?


1.
#include
2.
using namespace std;
3.
template
4.
class XYZ
5.
{
6.
public:
7.
void putPri();
8.
static T ipub;
9.
private:
10.
static T ipri;
11.
};
12.
template
13.
void XYZ::putPri()
14.
{
15.
cout
  1.    template
  2.    class
  3.    no specialization
  4.    None of the mentioned
 Discuss Question
Answer: Option A. -> template

Answer:d
Explanation:
In this program, We are passing the value of specified type and printing it by specialization.
Output:
$ g++ spec2.cpp
$ a.out
1
1
1.2


Question 6.


What is the output of this program?


1.
#include
2.
using namespace std;
3.
template
4.
T multIt(T x)
5.
{
6.
for(int ii = 0; ii < count; ii++)
7.
{
8.
x = x * x;
9.
}
10.
return x;
11.
};
12.
int main()
13.
{
14.
float xx = 2.1;
15.
cout
  1.    2.1
  2.    378.228
  3.    2.1: 378.228
  4.    None of the mentioned
 Discuss Question
Answer: Option C. -> 2.1: 378.228

In this program, We specifed the type in the template function. We need to compile this program by adding -std=c++0x.
Output:
$ g++ -std=c++0x spec1.cpp
$ a.out
2.1: 378.228


Question 7.

Which is similar to template specialization?


  1.    template
  2.    function overloading
  3.    function template overloading
  4.    None of the mentioned
 Discuss Question
Answer: Option C. -> function template overloading

None


Question 8.

Which is called on allocating the memory for array of objects?


  1.    destructor
  2.    constructor
  3.    method
  4.    None of the mentioned
 Discuss Question
Answer: Option B. -> constructor

When you allocate memory for an array of objects, the default constructor must be called to 

construct each object. If no default constructor exists, you’re stuck needing a list of pointers 

to objects.


Question 9.

What is meant by template specialization?


  1.    It will have certain data types to be fixed.
  2.    It will make certain data types to be dynamic.
  3.    Certain data types are invalid
  4.    None of the mentioned
 Discuss Question
Answer: Option A. -> It will have certain data types to be fixed.

In the template specialization, it will make the template to be specific for some data types.

Question 10.


What is the output of this program?


1.
#include
2.
using namespace std;
3.
template
4.
inline T square(T x)
5.
{
6.
T result;
7.
result = x * x;
8.
return result;
9.
};
10.
template
11.
string square(string ss)
12.
{
13.
return (ss+ss);
14.
};
15.
int main()
16.
{
17.
int i = 2, ii;
18.
string ww("A");
19.
ii = square(i);
20.
cout
  1.    2:4AA
  2.    2:4
  3.    AA
  4.    2:4A
 Discuss Question
Answer: Option A. -> 2:4AA

Template specialization is used when a different and specific implementation is to be used for a 

specific data type. In this program, We are using integer and character.
Output:
$ g++ spec.cpp
$ a.out
2:4AA


Latest Videos

Latest Test Papers