Sail E0 Webinar

MCQs

Total Questions : 5
Question 1.

From where does the template class derived?


  1.    regular non-templated C++ class
  2.    templated class
  3.    a or b
  4.    none of the mentioned
 Discuss Question
Answer: Option C. -> a or b

None.


Question 2.

What can be passed by non-type template parameters during compile time?


  1.    int
  2.    float
  3.    constant expression
  4.    none of the mentioned
 Discuss Question
Answer: Option C. -> constant expression

Non-type template parameters provide the ability to pass a constant expression at compile time. 

The constant expression may also be an address of a function, object or static class member.


Question 3.


What is the output of this program?


1.
#include
2.
using namespace std;
3.
template
4.
void loopIt(T x)
5.
{
6.
int count = 3;
7.
T val[count];
8.
for (int ii=0; ii < count; ii++)
9.
{
10.
val[ii] = x++;
11.
cout
  1.    int
  2.    float
  3.    constant expression
  4.    none of the mentioned
 Discuss Question
Answer: Option C. -> constant expression

Answer:d
Explanation:
In this program, We are using the for loop to increment the value by 1 in the function template.
Output:
$ g++ ftemp5.cpp
$ a.out
2.1
3.1
4.1


Question 4.


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.
int main()
11.
{
12.
int i, ii;
13.
float x, xx;
14.
double y, yy;
15.
i = 2;
16.
x = 2.2;
17.
y = 2.2;
18.
ii = square(i);
19.
cout
  1.    int
  2.    float
  3.    constant expression
  4.    none of the mentioned
 Discuss Question
Answer: Option C. -> constant expression

Answer:a
Explanation:
In this program, We are passing the values and calculating the square of the value by using the function template.
Output:
$ g++ ftemp4.cpp
$ a.out
2 4
2.2 4.84


Question 5.


What is the output of this program?



1.
#include
2.
using namespace std;
3.
template
4.
class TestVirt
5.
{
6.
public:
7.
virtual type TestFunct(type Var1)
8.
{
9.
return Var1 * 2;
10.
}
11.
};
12.
int main()
13.
{
14.
TestVirt Var1;
15.
cout

  1.    100
  2.    200
  3.    50
  4.    none of the mentioned
 Discuss Question
Answer: Option B. -> 200

In this program, We are using class to pass the value and then we are manipulating it.
Output:
$ g++ ftemp3.cpp
$ a.out
200


Latest Videos

Latest Test Papers