#include<stdio.h>
#include<conio.h>
int *x()
{
int y=10;
return (&y);
}
void main()
{
int *p;
clrscr();
p=x();
printf("%d",*p); // Output 10
getch();
}
Here when we call x() function, activation record of x is pushed onto the stack. When we come out of that function, the activation record and all the local variables inside it are destroyed. So, how are we able to access the value of y in main function after coming out of x function ? The output value should be some garbage value as "y" variable is destroyed.