No one has been able to answer this yet!!
Hi, I haven't been able to find a satisfactory answer yet!, but what would this code do?
Code:
void main()
{
int a;
a = foo();
printf("%d",a);
}
int foo()
{
int *p;
p = malloc(1*sizeof(int));
*p = 5;
return (*p);
}
So I guess the idea is , what happens to "p" at the termination of the function call? since its a stack variable, it gets popped, but the malloc'd memory is on the heap, which still persists, I think? and since you're returning the dereferenced variable, it should be good, right?