I am curious on how the return values work.
I know the basics.
Can someone explain how the data flow works here?Code:int x; int getMyInt() { return x; } void test() { modify(getMyInt()); } void modify(int y) { y = 3; }
I am curious on how the return values work.
I know the basics.
Can someone explain how the data flow works here?Code:int x; int getMyInt() { return x; } void test() { modify(getMyInt()); } void modify(int y) { y = 3; }
'modify' has no effect on the variable passed into it because you are passing by value.
To see why y is just a copy of the parameter, consider that it is perfectly okay to do:This clearly does not make 42 equal to 3.Code:modify(42);
What you want is to pass by reference.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"