函数指针和函数指针数组
2017-02-17 14:32
253 查看
直接看代码
#include <stdio.h>
typedef int (* P_PRINT)(int); //先定义函数指针类型
int fun1(int i)
{
return i;
}
int fun2(int i)
{
return i;
}
int fun3(int i)
{
return i;
}
int main()
{
P_PRINT p_print[3];//定义函数指针变量,这个地方也可以直接定义
int (*p_print[3])(int);//这个和上边的定义是一个效果,不过上边的定义可以重复使用
int i = 0;
p_print[0] = fun1;
p_print[1] = fun2;
p_print[2] = fun3;
for(i = 0; i < 3; i++)
{
printf("resutl is %d\n",(*p_print[i])(i));
}
return 0;
}
#include <stdio.h>
typedef int (* P_PRINT)(int); //先定义函数指针类型
int fun1(int i)
{
return i;
}
int fun2(int i)
{
return i;
}
int fun3(int i)
{
return i;
}
int main()
{
P_PRINT p_print[3];//定义函数指针变量,这个地方也可以直接定义
int (*p_print[3])(int);//这个和上边的定义是一个效果,不过上边的定义可以重复使用
int i = 0;
p_print[0] = fun1;
p_print[1] = fun2;
p_print[2] = fun3;
for(i = 0; i < 3; i++)
{
printf("resutl is %d\n",(*p_print[i])(i));
}
return 0;
}
相关文章推荐
- 函数指针 和 函数指针数组 和 函数指针数组
- 函数指针数组与返回数组指针的函数
- (转载)函数指针及函数指针数组的妙用
- C++ primer(七)--函数、C++的编程模块 函数指针 函数指针数组 typedef
- 变量、指针变量、指针数组、数组指针、函数指针、函数指针数组
- 关于函数指针数组与返回数组指针的函数
- 函数指针与函数指针数组的定义与使用
- 转:函数指针,函数指针数组,函数指针数组的指针
- (转载)函数指针及函数指针数组的妙用
- 指针数组 数组指针 函数指针 函数指针数组
- 函数指针与指针函数的区别及函数指针数组
- 函数指针—指针函数 数组指针—指针数组 类模板—模板类 函数模板——模板函数 的区别
- 转:关于函数指针数组与返回数组指针的函数
- 函数指针和指针函数,函数指针数组
- 指针数组、数组指针、指针函数、函数指针、函数指针数组解析
- 函数指针与函数指针数组的使用方法
- 关于函数指针及函数指针数组
- 关于函数指针数组与返回数组指针的函数
- 函数指针与函数指针数组的使用方法
- 函数指针 和 函数指针数组 和 函数指针数组