Examveda

What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
class A{
	mutable int a;
public:
	A(){
		cout<<"Default constructor called\n";
	}
	A(const A& a){
		cout<<"Copy Constructor called\n";
	}
};
int main(int argc, char const *argv[])
{
	A obj;
	A a1 = obj;
	A a2(obj);
}

A. Default constructor called
Copy Constructor called

B. Default constructor called
Copy Constructor called
Copy Constructor called

C. Default constructor called
Default constructor called
Copy Constructor called

D. Copy Constructor called
Default constructor called
Copy Constructor called

Answer: Option B


Join The Discussion

Related Questions on Constructors and Destructors in C plus plus