回调函数
来源:互联网 发布:知乎无法登陆 编辑:程序博客网 时间:2024/06/11 13:19
函数参数也可以是函数指针变量。指针变量的常见用途之一就是把指针作为参数传递到其他函数,指向函数的指针也可以作为参数,以实现函数地址的传递。
#include<stdio.h>
#include<stdlib.h>
int add(int a,int b)
{
return a+b;
}
int sub(int a, int b)
{
return a - b;
}
int mul(int a, int b)
{
return a*b;
}
int dev(int a, int b)
{
return a / b;
}
typedef int(*fptr)(int,int);//定义一个函数指针类型fptr
void calculator(fptr funptr/*函数指针作为函数参数*/, int a, int b)
{
printf("the result is %d\n", funptr(a, b));
}
int main()
{
int a = 5,b = 2;
calculator(add, a, b);//函数名也是函数指针,可以作为函数参数
calculator(sub, a, b);
calculator(mul, a, b);
calculator(dev, a, b);
system("pause");
return 0;
}
0 0
- .NET 回调函数
- 回调函数
- 回调函数
- 回调函数概念
- 回调函数
- 回调函数
- 回调函数
- 回调函数 相关
- delphi 回调函数
- 回调函数
- 回调函数
- 回调函数学习
- 回调函数
- 关于回调函数
- 透析回调函数
- 回调函数
- 什么是回调函数
- 回调函数
- android混合开发:cordova的安装使用
- 连接Mysql提示Can’t connect to local MySQL server through socket的解决方法
- AngularJs 之过滤器($filter)
- AndroidStudio 抓异常快捷键
- 数据库学习
- 回调函数
- linux ls和 ll 命令
- JDK1.8源码逐字逐句带你理解WeakHashMap底层
- 前端js和css的压缩合并之grunt
- 解决Idea 2016打开Andorid项目报java home is different
- The operator of C++ : sizeof
- 多线程系列提高(2)--线程安全性
- JVM性能调优
- Mysql数据库int(1)和tinyint(1)的区别&&扩展阅读