New course! Every coder should learn Generative AI!
Try a free lesson+ 2
Output please explain me
int x(int &a, int &b) {a=3;b=4;return a+b;} int main() { int a=2; int b=7; int c=x(a,a); cout<<a<<b<<c; return 0; } output 478 my guess 477
2 Answers
+ 4
When you send data a to function x. At first line value of a become 3. On second line its value change to 4. and there is only one variable send. When it write a+b that mean it access only one variable address that is a.
here a+b become a+a
And thus it return 8.
So value of
a=4
b=7 (does not change because it is not send to function)
c=8
+ 1
thanks I missed that only one variable was sent so a+b will be a+a