#include<stdio.h>
int *sample();
int main(void)
{
int *p;
p=sample();
printf("%d",*p);
return 0;
}
int *sample()
{
int *p,x=10;
p=&x;
return p;
}
In the code above x
is local variable. When I compiled above with gcc I'm getting output:
10
A local variable is only alive in the function where it is declared and as the control comes out of function local variable should be de-allocated. But this is not happening. wWy its printing 10? Can anyone explain this behaviour?