C++ Template Question:
Download Questions PDF

What is the output of this program?

#include <iostream>
using namespace std;
template <class T, int N>
class mysequence
{
T memblock [N];
public:
void setmember (int x, T value);
T getmember (int x);
};
template <class T, int N>
void mysequence<T,N> :: setmember (int x, T value)
{
memblock[x] = value;
}
template <class T, int N>
T mysequence<T,N> :: getmember (int x)
{
return memblock[x];
}
int main ()
{
mysequence <int, 5> myints;
mysequence <double, 5> myfloats;
myints.setmember (0, 100);
myfloats.setmember (3, 3.1416);
cout << myints.getmember(0) << 'n';
cout << myfloats.getmember(3) << 'n';
return 0;
}
a) 100
b) 3.1416
c) 100
3.1416
d) none of the mentioned

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

Answer:

c) 100

Download C++ Template Interview Questions And Answers PDF

Previous QuestionNext Question
What is the validity of template parameters?
a) inside that block only
b) inside the class
c) whole program
d) any of the mentioned
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