Parameter pointer retrieve function local variable address
So, before I dive into the question, here's the premise: void myFunc(int *ip) { int a = 2; *ip = a; } int main() { int catcher; myFunc(&catcher); printf("%i\n", catcher); return 0; } What I'm trying to achieve in the above example is use the pointer parameter (*ip) to store the address (point to) what the variable (a) is. Then catch the variable back in the main function, and use it. I know it's possible because I've made it work several times, but my assignment code has gotten very complex, and I'm getting segmentation fault detection from my GDB debugger. I'm pretty well versed with pointers and memory management, but this is slightly out of my scope in terms of understanding what is happening. My guess is that when the myFunc() frame stack is popped, the pointer points to nothing. Could someone help me understand and achieve this?