Examveda
Examveda

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

A. 5

B. 10

C. Error

D. Segmentation fault

Answer: Option C


Join The Discussion

Related Questions on Constructors and Destructors in C plus plus