回调函数
来源:互联网 发布:淘宝加盟商 编辑:程序博客网 时间:2024/06/09 22:03
回调函数通俗的解释:
普通函数:你所写的函数调用系统函数,你只管调用,不管实现。
回调函数:系统调用你所写的函数,你只管实现,不管调用。
形象的比喻下吧:
你到一个商店买东西,刚好你要的东西没有货,于是你在店员那里留下了你的电话,过了几天店里有货了,店员就打了你的电话,然后你接到电话后就到店里去取了货。
在这个例子里,你的电话号码就叫回调函数,你把电话留给店员就叫登记回调函数,店里后来有货了叫做触发了回调关联的事件,店员给你打电话叫做调用回调函数,你到店里去取货叫做响应回调事件。
例题:
#include <stdlib.h>#include <stdio.h>int Test1(){ int i; for (i=0; i<30; i++) { printf("The %dth charactor is:%c\n", i, (char)('a'+i%26)); } return 0;}int Test2( int num){ int i; for (i=0; i< num; i++) { printf("The %dth charactor is:%c\n", i, (char)('a'+i%26)); } return 0;}void Caller1( int (*ptr)() ) //指向函数的指针作函数参数 { (*ptr)();}void Caller2(int n, int (*ptr)(int) ) //指向函数的指针作函数参数,这里第一个参数是为指向函数的指针服务的, { //不能写成void Caller2(int (*ptr)(int n)),这样的定义语法错误。 (*ptr)(n);}int main(){ printf("***************************\n"); Caller1(Test1); //相当于调用Test1(); printf("&&&&&&&**********************\n"); Caller2(5, Test2); //相当于调用Test2(5); return 0;}
0 0
- .NET 回调函数
- 回调函数
- 回调函数
- 回调函数概念
- 回调函数
- 回调函数
- 回调函数
- 回调函数 相关
- delphi 回调函数
- 回调函数
- 回调函数
- 回调函数学习
- 回调函数
- 关于回调函数
- 透析回调函数
- 回调函数
- 什么是回调函数
- 回调函数
- Unity3D说明文档翻译-Lighting Overview
- c#调用外部dll详解
- 推荐一个php在线测试地址
- Java基本类型与引用类型 以及 Java内存知识整理
- C# winfrom简单的题目
- 回调函数
- 使用css伪元素的一些遐想
- ubuntu与win7在局域网下共享文件
- Cenos7_Install_Mysql5.7
- CSDN日报20170411
- 全息电话会议开源项目LiveScan3D-Hololens
- PAT乙级(Basic Level)真题 数素数(素数筛法)
- c++基础 类的设计
- javascript中模拟实现java语言中的map