MCQs > IT & Programming > C++ > Output of the following code? #include using namespace std; class myclass { private: int number; public: myclass() { number = 2; } int &a() { return number; } }; int main() { myclass m1,m2; m1.a() = 5; m2.a() = m1.a(); cout << m2.a(); return 0; }

C++ MCQs

What will happen when the following code is compiled and executed?
#include<iostream>
using namespace std;
class myclass
{
private:
int number;
public:
myclass()
{
number = 2;
}
int &a()
{
return number;
}
};
int main()
{
myclass m1,m2;
m1.a() = 5;
m2.a() = m1.a();
cout << m2.a();
return 0;
}

Answer

Correct Answer: The printed output will be 5

Explanation:

Note: This Question is unanswered, help us to find answer for this one

C++ Skill Assessment

Overall Skill Level-Poor

Your Skill Level: Poor

Retake Quizzes to improve it

More C++ MCQ Questions

search

C++ Skill Assessment

Overall Skill Level-Poor

Your Skill Level: Poor

Retake Quizzes to improve it