C++ Template Question:
Download Questions PDF

What is the output of this program?

#include <iostream>
using namespace std;
template <typename T, int count>
void loopIt(T x)
{
T val[count];
for(int ii = 0; ii < count; ii++)
{
val[ii] = x++;
cout << val[ii] << endl;
}
};
int main()
{
float xx = 2.1;
loopIt<float, 3>(xx);
}
a) 2.1
b) 3.1
c) 4.1
d) 2.1
3.1
4.1

C++ Template Interview Question
C++ Template Interview Question

Answer:

d) 2.1
3.1
4.1

Download C++ Template Interview Questions And Answers PDF

Previous QuestionNext Question
What is the output of this program?

#include <iostream>
using namespace std;
template <class type>
class Test
{
public:
Test()
{
};
~Test()
{
};
type Funct1(type Var1)
{
return Var1;
}
type Funct2(type Var2)
{
return Var2;
}
};
int main()
{
Test<int> Var1;
Test<double> Var2;
cout << Var1.Funct1(200);
cout << Var2.Funct2(3.123);
return 0;
}
a) 100
b) 200
c) 3.123
d) 200 3.123
Which parameter is legal for non-type template?
a) pointer to member
b) object
c) class
d) none of the mentioned