What happens to the stack frame after a function is called? I have a function that returns the address of a local variable - should I be able to do that, or is the stack frame destroyed after the function is returned? Here is my code - I expected to get the wrong result, but I got the right result instead.
#include<stdio.h>
#include<stdlib.h>
int* sum(int a,int b)
{
int x=a+b;
return &x;
}
int main()
{
int*a;
int x=5,y=6;
a=sum(x,y);
printf("%d",*a);
return 0;
}