I am not able to understand an example in Let us C by Yashwant Kanetkar. Here is the code snippet:
main()
{
int *j;
int *fun();
j = fun();
// If we add a function call here, the print statement prints a garbage value.
printf("\n%d",*j);
}
int *fun()
{
int k = 35;
return (&k);
}
Now in the above code, I am not able to understand why having a function call before the printf statement results in printing a garbage value. I have a vague idea that as the returned value points to a memory location in the stack, something goes wrong when another function is called before printing this value. But I am not able to clearly visualize what happens here. Please help.