一、
定义了一个结构体
struct abc{
int (*a)();
int (*b)();
int (*c)();
};
要给这些函数指针成员赋值
struct abc abcd={
.a=fun1,
.b=fun2,
.c=fun3,
};
二、
#include <stdio.h>
typedef struct test
{
void (*p)(void);
void (*q)(void);
void (*y)(void);
}test;
void f1(void)
{
printf("f1\n");
}
void f2(void)
{
printf("f2\n");
}
void f3(void)
{
printf("f3\n");
}
int main(void)
{
test aa = {
p : f1, //方法1
.q = f2, //方法2, 一般这种方式在全局变量初始化的时候常用
};
aa.y = f3; //方法3
aa.p();
aa.q();
aa.y();
return 0;
}