Question

USLUR #include <iostream using namespace std; /** @return a reference to the smaller of the two arguments */ int& maxi(int&x,
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Line by line explanation

1) int a=10, b=20;

assigns 10 and 20 to a and b respectvely.


2) maxi(a,b)=5;

calling maxi(a,b) returns the reference of greater variable, in this case b is greater. Therefore maxi(a,b) returns b. Which is then assigned to 5. Therefore now value of a = 10, b=5.


3) cout<<a<<" "<<b<<endl;

Print the values a and b. 10 5 gets printed.

4) maxi(a,b)+=6;

maxi(a,b) returns a as 10 is greater than 5. Now the expression becomes a = a+6. Therefore new value of a is 10+6 = 16. And b remains 5.

5) cout<<a<<" "<<b<<endl;

Print a and b. 16 5 gets printed.

6) ++maxi(a,b);

Again maxi(a,b) returns reference to a as 16 is greater than 5. Therefore expression now becomes ++a, which is same as a=a+1. Now a become 16+1=17, and b remains 5.

7) cout<<a<<" "<<b<<endl;

print a and b. 17 5 gets printed.

OUTPUT SS:

185 165 175

Add a comment
Know the answer?
Add Answer to:
USLUR #include <iostream using namespace std; /** @return a reference to the smaller of the two...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT