这个程序有点绕
#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)
{
INCp=&inc;
int temp=p(arg1);
fun(&temp,&arg1,arg2);
printf("%d\n",*arg2);
}
main()
{
int a;
show(multi,10,&a);
return 0;
}
书上给的答案是110
但是我无法运行
提示有三个错误
1>c:\users\yaphets_\documents\visual studio 2005\projects\huawei1\huawei1\a.c(14) : error C2065: 'INCp' : undeclared identifier
1>c:\users\yaphets_\documents\visual studio 2005\projects\huawei1\huawei1\a.c(14) : warning C4047: '=' : 'int' differs in levels of indirection from 'int (__cdecl *)(int)'
1>c:\users\yaphets_\documents\visual studio 2005\projects\huawei1\huawei1\a.c(15) : error C2143: syntax error : missing ';' before 'type'
1>c:\users\yaphets_\documents\visual studio 2005\projects\huawei1\huawei1\a.c(16) : error C2065: 'temp' : undeclared identifier #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)
{
int (*p)(int)=&inc;
int temp=p(arg1);
fun(&temp,&arg1,arg2);
printf("%d\n",*arg2);
}
main()
{
int a;
show(multi,10,&a);
return 0;
}
页:
[1]