Examveda

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
template <class T>
class XYZ
{
    public:
    void putPri();
    static T ipub;
    private:
    static T ipri; 
};
template <class T>
void XYZ<T>::putPri()
{
    cout << ipri++ << endl;
}
template <class T> T XYZ<T>::ipub = 1;
template <class T> T XYZ<T>::ipri = 1.2;
int main()
{
    XYZ<int> a;
    XYZ<float> b;
    a.putPri();
    cout << a.ipub << endl;
    b.putPri();
}

A. 1

B. 1.2

C. 1
1.2

D. 1
1
1.2

Answer: Option D


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