c语言复杂函数声明的举例
有一个复杂函数声明:int (*f(float (*)(long),char *))(double);
怎样设计一个例子来调用该声明呢?
百思不得解,难。。。
程序代码:#include "stdio.h"
#include "math.h"
typedef int (*RETURN_TYPE)(double);
typedef float (*PARAMETER_TYPE)(long);
RETURN_TYPE f(PARAMETER_TYPE,char *);
float f2(long n);
int f3(double d);
int main(void)
{
int i;
i=(f(f2,"abc"))(0);
printf("%d\n",i);
return 0;
}
float f2(long n)
{
if(n==0) return 0.0;
else return 1.0;
}
int f3(double d)
{
if(fabs(d)<1e-6) return 0;
else return 1;
}
RETURN_TYPE f(PARAMETER_TYPE ff,char *s)
{
float f=ff(0);
if(fabs(f)<1e-6) printf("%s\n",s);
return f3;
}
//或者不用typedef
#include "stdio.h"
#include "math.h"
int (*f(float (*)(long),char *))(double);
float f2(long n);
int f3(double d);
int main(void)
{
int i;
i=(f(f2,"abc"))(0);
printf("%d\n",i);
return 0;
}
float f2(long n)
{
if(n==0) return 0.0;
else return 1.0;
}
int f3(double d)
{
if(fabs(d)<1e-6) return 0;
else return 1;
}
int (*f(float (*ff)(long n),char *s))(double d)
{
float f=ff(0);
if(fabs(f)<1e-6) printf("%s\n",s);
return f3;
}
[此贴子已经被作者于2019-6-11 17:04编辑过]