So, I'm really frustrated with this problem. I desperately need some good explanation about this. Why does the calling function does not reflect the change done in the called function? despite the fact that I pass the variable via pointer. Any explanations please. Thanks in advance.
#include <iostream>
using namespace std;
void foo(int *x) {
int *y = new int(999);
x = y;
}
int main(void) {
int *x = new int(1);
foo(x);
cout << *x << endl;
cin.get();
return 0;
}
In main: x = 1;
In foo: x = 999;
In main: x = 1;
Why ?
and How will I reflect the change on the calling function (without using RETURN) ?
THANKS.