Examveda

What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
class A
{
	static int a;
    public:
	void show()
        {
		a++;
		cout<<"a: "<<a<<endl;
	}
};
 
int A::a = 5;
 
int main(int argc, char const *argv[])
{
	A a;
	return 0;
}

A. Error as a private member a is referenced outside the class

B. Segmentation fault

C. No output

D. Program compiles successfully but gives run-time error

Answer: Option C


Join The Discussion

Related Questions on Classes and Objects in C plus plus