Even I have similar problem:
int (*pfun)(void);
int *pInt = 0;
void fun1()
{
int i = 5; /* Local to fun1*/
printf("Outer function");
pInt = &i; /* As I know address of local variable is valid till function execution */
int fun2()
{
printf("innerfunction");
printf("%d", *pInt);
}
/* fun2 address assign to pfun so that It can be called even after completion of fun1 */
pfun = fun2;
}
int main()
{
fun1();
pfun();
return 0;
}
Can someone please explain ? I am getting *pInt value 5.