void foo(int** ptr) {
int value = 4;
*ptr = &value;
// **ptr = value;
}
int main(void) {
int value = 7;
int* ptr = &value;
foo(&ptr);
cout << *ptr << endl; // 4
return 0;
}
My Question is - as the value = 4
is no longer valid/out of scope after returning from foo
, why *ptr
is showing 4
instead of some garbage value?