Examveda

What will be the output of the following C++ code?
#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. 4.14

Answer: Option C


Join The Discussion

Related Questions on C plus plus miscellaneous

What is the difference between '++i' and 'i++' in C++?

A. None of the above

B. They both have the same effect

C. '++i' increments the value of 'i' before returning it, while 'i++' increments the value of 'i' after returning it

D. '++i' increments the value of 'i' after returning it, while 'i++' increments the value of 'i' before returning it