Q. What is the output of the following C++ code?
Code:#include<iostream>
using namespace std;
class MyClass {
int &val;
public:
MyClass (int &v) { val = v; }
int getValue() { return val; }
};
int main()
{
int v = 10;
MyClass obj(v);
cout << obj.getValue() << " ";
v = 20;
cout << obj.getValue() << endl;
return 0;
}
β
Correct Answer: (D)
Compilation error