So, if you are looking to do something like:
int* someFunction()
{
int *ip[10];
ip[0] = malloc(sizeof(int));
*ip[0] = 22;
return ip[0];
}
The value 22 would "survive". But this is really bad form. You should
always do malloc and free within the same scope, not in different
functions. Also, it's a good idea to always make your functions return
an int that represents an error code. So something like this would be
much better:
This is not true. Sorry.
In any system of any size, memory allocations are frequently handled
in an optimised system memory handler. In addition the creation of an
object in the system does not immediatley mean that good prorgamming
practices insist that that same function also destroys it. A good example
might be a message based window system : the code with creates the
window/dialog is never (almost) responsible for deleting it. A system
dealing with Business Objects based on a database. Lots of things.
malloc is not immitiating an automatic stack variable and it not
intended to. That said, if using malloc to create a temporary buffer,
of course it makes sense to clean up in the same scope as it was
created if it is no further needed