Here, I have a function f() that locally defines an integer x and a pointer to it, pointer_x. And it returns that pointer. I then attempt to dereference the pointer, and it still gives me the correct integer that is pointed to by that pointer. My question is, if it is illegal for a function to locally declare an array and return that array (due to the deallocation of the stack frame as that function returns), why is it legal for a function to declare a pointer and return that pointer?
I am under the impression that an array is basically a pointer.
int *f();
int main(void){
int *test;
test = f();
printf("%d", *test); //prints 0
}
int *f(){
int x = 0;
int *pointer_x = &x;
return pointer_x;
}