Does such a function result in a dangling pointer?
int *foo () {
int a[2] = {2, 3};
int *p = NULL;
p = a;
return p;
}
Yes. You are returning a pointer to an array with automatic storage duration. When the function returns the pointer is invalid.