例1:
//定义结构体
atruct temp{
int a;
void (*initial)();
}
//定义函数
void func(void)
{
printf("hello world");
}
void main()
{
temp ll;
ll.initial = func;
ll.initial();
}
打印结果:
hello world
例2:
atruct temp{
int *a;
void (*initial)();
}
void func(void)
{
printf("hello world");
}
temp 11={
.a = 12,
.initial = func,
};
void main()
{
ll.initial();
}
打印结果:
hello world
另外:
定义的指针结构体用->,定义的结构体用.
exp:
atruct temp{
int a;
void (*initial)();
}
//调用a的值
temp ll;
ll.a;
temp *l2;
l2->a;