ret is a local variable, you can't pass its address because it's gone when get_local goes out of scope. If you want to return local variable, return by value.
Originally Posted by _Mike
Unless you allocate the memory on the heap, then yes, you can return the pointer. But that is a pretty bad practice becuase you will forget to free it later.
int get_local_var(int i)
int ret = i;
// do somethign else to ret here
int * get_local_var(int i)
int* ret=malloc(sizeof (int));
return p; <-------- have to free this in main() or whereever. When you have a hundred of these pointers, it becomes impossible to keep track of them.