0
How does "a" become 4, or it's mistake? I thought it should be 2 O.o
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; } RESULT: 478
4 Antworten
+ 1
I'd say you need to return a integer in the x method or make it an void.
+ 1
Yes I get it, tnx :)
0
yes, i forgot to write it, but it's not the problem
0
ok using int &b or int &a in int x(...) you create an int with the same address as a in int main(), so a and b in int x(...) and the other a, too, are the same, but the last assignment is b = 4, which sets all three ints to the value 4
I hope you get what I mean