137、写出下列代码的输出内容
#include<stdio.h>
int inc(int a)
{
return(++a);
}
int multi(int*a,int*b,int*c)
{
return(*c=*a**b);
}
typedef int(FUNC1)(int in);
typedef int(FUNC2) (int*,int*,int*);
void show(FUNC2 fun,int arg1, int*arg2)
{
FUNC1* INCp = &inc;
int temp = INCp(arg1);
fun(&temp,&arg1, arg2);
printf("%d\n",*arg2);
}
int main()
{
int a;
show(multi,10,&a);
return 0;
}show的第一个参数是函数指针,传过去的是multi函数的地址
FUNC1* INCp = &inc;吧inc函数地址付给INCp,所以tmp = 11;
所以fun(&temp,&arg1, arg2);等价于multi(&temp,&arg1, arg2);
*c = *a**b等价于 *c = (*a)*(*b)=110
本文通过一个具体的C语言程序示例,详细解析了如何使用函数指针进行参数传递,并展示了递增函数和乘法函数的组合使用。解释了代码中涉及的函数定义、类型定义以及函数指针调用的细节。
1万+

被折叠的 条评论
为什么被折叠?



