What will be the output of the following program in C++? #include 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(); }

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter12: Adding Functionality To Your Classes
Section12.2: Providing Class Conversion Capabilities
Problem 5E
icon
Related questions
Question

What will be the output of the following program in 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();
}

Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr