Question: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;
}
 

A Compile Error 

B The printed output will be 5 

C The printed output will be 0 

D The printed output will be 7 

+ Answer
+ Report
Total Preview: 1349

Copyright © 2024. Powered by Intellect Software Ltd