I know it is good to get in the habit of using the free()
function to destroy a pointer when you're done with it, but what happens if a pointer is returned from a function? I assume it doesn't send a copy over, because there is no opportunity to destroy it. Does the pointer "switch" scope to the calling function?
Example (useless code, beware):
int* getOne(){
int a = 1, *pA;
pA = &a;
return pA; //what happens to this
}
int main(){
printf("%i", getOne()); //uses data from the same addresses allocated to pA above?
return 0;
}