What will be the output of the following C++ code? [code] #include <iostream> using namespace std; class A{ public: A(){ cout<<"Constructor

Thảo Justin

New member
What will be the output of the following C++ code?
Code:
#include <iostream>  
using namespace std;
class A{
public:
	A(){
		cout<<"Constructor called";
	}
};
int main(int argc, char const *argv[])
{
	A *a;
	return 0;
}
A. Constructor called
B. Nothing printed
C. Error
D. Segmentation fault
 
Answer: b
Explanation: As we have declared a pointer variable for class A but we have not initialized the memory to that pointer and until the memory is not initialized the constructor for the pointer variable will not be called hence nothing is printed on the screen.
 

Tìm kiếm

Back
Top