I have below code running fine and giving out expected result. I have an additional query that how can I declare a pointer in my main function that holds the address of function A(funcA) ?
#include<stdio.h>
#include<stdlib.h>
int funcB (void)
{
printf("\n Now you are in function B \n ");
printf ("\n this function is for returning code value no matter what\n");
return -10;
}
int (*funcA(int x,int y)) (void)
{
printf( " I am in function A \n ");
static int sum;
sum=x+y;
printf ( "\n Sum is %d ",sum);
return &funcB;
}
int main ()
{
int (*fpb)(void);
int x;
fpb=funcA(10,15);
x=(*fpb)(); // Calling function B through fpb pointer
printf("\n Value stored in x for code is %d \n",x);
}
Result :
I am in function A Sum is 25 Now you are in function B this function is for returning code value no matter what Value stored in x for code is -10