PS:内容略显粗糙,是自己的学习笔记,一些简单粗俗的例子,代码仅供参考。
1.函数指针与结构体
#include <stdio.h>
typedef void (*func)(void);
struct test
{
int a;
func func1;
};
void hello()
{
printf("hello!");
}
int main()
{
test test1;
test1.func1 = hello;
test1.func1();
}
2.函数指针数组
#include <stdio.h>
typedef void (*func)(void);
void hello1()
{
printf("hello1");
}
void hello2()
{
printf("hello2");
}
func testfunc[]={hello1,hello2};
int main()
{
testfunc[1]();
testfunc[1]();
}