Quote Originally Posted by Daved
This is incorrect. The pointer is returned by value, meaning a copy of the pointer's value is returned and stored in whatever variable (if any) accepts it in the calling code. The pointer points at dynamic memory, which is not local to the function. So the dynamic memory still exists at the location stored by the pointer, even after the function exits. The allocated memory is still valid, and the location of that memory stored in the pointer can be returned from the function.
Thanks Daved for correcting me. I got the idea completely wrong.