+ 21

Explain this question please? Wht happened in this program explain please .

https://www.sololearn.com/post/417181/?ref=app

24th May 2020, 8:39 AM
YASH SHAH
YASH SHAH - avatar
6 Answers
+ 5
Because function x is called with same variable in position of both arguments, inside function variables a and b share same memory location. You can see that by adding test to function x: int x(int &a, int &b) { if(&a==&b) cout<<"Same address"<<endl; a=3; b=4; return a+b; } So first (a=3) both get value 3 and then (b=4) both get value 4.
24th May 2020, 12:04 PM
Uros Zivkovic
Uros Zivkovic - avatar
+ 3
This question has been asked before and read comments. checkout https://www.sololearn.com/Discuss/2307927/?ref=app
25th May 2020, 3:16 PM
đŸ’«AsđŸ’«
+ 1
comments are pretty great:))
26th May 2020, 4:11 AM
Aditya Gautam
Aditya Gautam - avatar