结构体中使用函数指针

#include "stdio.h" #include <stdlib.h>

//#if 0

void func(char *s)

{  

printf(s);

} //#endif

typedef struct {

 int age;

 char *name;

 void (*func)();

}student;

int main(void)

{

 student *lxl=malloc(sizeof(student));

 lxl->age=11;

 lxl->name="lxl";

 lxl->func=func;  

printf("hello world! ");

 lxl->func(lxl->name);

 free(lxl);

 return 0;

}

原文地址:https://www.cnblogs.com/luxiaolai/p/4910930.html