Call Stack - while a function returns reference of local variable to the calling function which is followed by the call to another function
===

#include<stdio.h>

    int *fun();
    int main()    
    {
    int *ptr;
    ptr=fun();
    printf("%d",*ptr);
    printf("%d",*ptr);
    }
    int * fun()
    {
    int k=4;//If auto then cannot print it two times.....stack will be changed
    return(&k);
    }

O/P: 4
    -2
Calling printf() for the first time prints the correct value.
Calling any function (even printf( ) ) immediately after the call to fun( ). This time printf( ) prints a garbage value. Why does this happen?Why do we not get a garbage value during the first print statement itself????