What will be the output of the following C++ code?

#include <iostream>
using namespace std;
class Test
{
public:
    static int count;
};
int Test::count = 10;
int main()
{
    Test a, b;
    a.count++;
    cout << b.count;
    return 0;
}
                        

Options

  • A. 10
  • B. 11
  • C. 12
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

B. 11

Detailed Explanation

Correct Answer: Option B

Explanation:
A static data member belongs to the class and is shared by all its objects. Initially, count is 10. The expression a.count++ increments the shared value to 11, so accessing b.count prints 11.