#include <stdio.h>
typedef void (*func)();//函数指针变量一般用typedef来简单化
void fun1();
typedef struct s
{
func f;结构体成员变量想作为函数时,可定义函数指针变量
} strc;
func fun2(strc *p)
{
return p->f;
}
int main()
{
strc *st,strc;
st=&strc;
st->f=fun1;
func stp;
stp=fun2(st);
printf("%d,,,%d\n",st->f,stp);
printf("%d\n",st->f);
printf("%d\n",strc);
printf("%d\n",&strc);
return 0;
}
void fun1()
{
puts("This is the first function!");
typedef void (*func)();//函数指针变量一般用typedef来简单化
void fun1();
typedef struct s
{
func f;结构体成员变量想作为函数时,可定义函数指针变量
} strc;
func fun2(strc *p)
{
return p->f;
}
int main()
{
strc *st,strc;
st=&strc;
st->f=fun1;
func stp;
stp=fun2(st);
printf("%d,,,%d\n",st->f,stp);
printf("%d\n",st->f);
printf("%d\n",strc);
printf("%d\n",&strc);
return 0;
}
void fun1()
{
puts("This is the first function!");
}
结果: