Suppose I have allocated memory to some pointer in a function foo:
foo
void foo() { // ... int *ptr = malloc(20*sizeof(int)); b
No. You have to store that information yourself when you malloc().
malloc()