以下代码正常运行并输出预期结果。 我有一个额外的问题,如何在我的主函数中声明一个指针,它保存函数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);
}
结果:
我在函数A中
总和为25 现在你在函数B中
这个函数是用来返回代码值的,无论如何
存储在x中的代码值为-10