I had the following code, however I don't understand what and why it outputs what it does.
int main(){
int *i;
int *fun();
i=fun();
printf("%d\n",*i);
printf("%d\n",*i);
}
int *fun(){
int k=12;
return(&k);
}
The output is 12 and a garbage value. Can somebody explain the output?
Shouldn't it return garbage values both times?
I know that k is local to fun(), so it would be stored on a stack and that it would be destroyed when fun() goes out of scope. What concept am I missing here?