C++ | Static Keyword | Question 1

Last Updated :
Discuss
Comments
Predict the output of following C++ program. C
#include <iostream>
using namespace std;

class Test
{
    static int x;
public:
    Test() { x++; }
    static int getX() {return x;}
};

int Test::x = 0;

int main()
{
    cout << Test::getX() << " ";
    Test t[5];
    cout << Test::getX();
}
0 0
5 5
0 5
Compiler Error
Share your thoughts in the comments