Examveda

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
template <class T>
class Test
{
  private:
    T val;
  public:
    static int count;
    Test()  {   
    	count++;   
    }
};
template<class T>
int Test<T>::count = 0;
int main()
{
    Test<int> a;
    Test<int> b;
    Test<double> c;
    cout << Test<int>::count << endl;
    cout << Test<double>::count << endl;
    return 0;
}

A. 2
1

B. 1
2

C. 1
1

D. 2
2

Answer: Option A


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