c/指针函3
来源:互联网 发布:淘宝关键词怎么优化 编辑:程序博客网 时间:2024/06/05 20:41
// test_function_p2.cpp : Defines the entry point for the console application.
//函数指针同样可以作为参数传递给函数的,下面的列子,仔细阅读你将会它的用处,稍加推理就可以很方便我们进行一些复杂的变成工作
#include "stdafx.h"
#include <IOSTREAM>
#include <STRING>
using namespace std;
int test(int);
int test2(int(*ra)(int),int);
int main(int argc, char* argv[])
{
cout<<test<<endl;
typedef int(*fp)(int);
fp fpi;
fpi=test;//fpi赋予test函数的内存地址
cout<<test2(fpi,1)<<endl;//这里调用test2函数的时候,把fpi所存储的函数地址(test的函数地址)传递给了test 的第一个形参
cin.get();
return 0;
}
int test(int a){
return a-1;
}
//这里定义了一个名字为ra的函数指针
int test2(int(*ra)(int),int b){
int c=ra(10)+b;//在调用之后,已经指向fpi所指向的函数地址鸡test函数
return c;
}
//函数指针同样可以作为参数传递给函数的,下面的列子,仔细阅读你将会它的用处,稍加推理就可以很方便我们进行一些复杂的变成工作
#include "stdafx.h"
#include <IOSTREAM>
#include <STRING>
using namespace std;
int test(int);
int test2(int(*ra)(int),int);
int main(int argc, char* argv[])
{
cout<<test<<endl;
typedef int(*fp)(int);
fp fpi;
fpi=test;//fpi赋予test函数的内存地址
cout<<test2(fpi,1)<<endl;//这里调用test2函数的时候,把fpi所存储的函数地址(test的函数地址)传递给了test 的第一个形参
cin.get();
return 0;
}
int test(int a){
return a-1;
}
//这里定义了一个名字为ra的函数指针
int test2(int(*ra)(int),int b){
int c=ra(10)+b;//在调用之后,已经指向fpi所指向的函数地址鸡test函数
return c;
}
0 0
- c/指针函3
- 【C++】指针(3):指针&数组
- C语言基础:C语言指针(3) - 指针的指针
- C语言 指针3
- C指针原理(3)
- c和指针(3)
- C指针专题3
- C指针小结3
- C语言指针3-函数指针
- 娓娓道来c指针 (3)指针和数组
- C和指针(3)指针
- 娓娓道来c指针 (3)指针和数组
- [C/C++]指针详解(3) — 指针表达式
- C语言指针详述(3)
- 初识C指针(3)
- 《c和指针》读书笔记3
- C语言指针(3)
- 读书笔记:C和指针3
- PAT3-08. 堆栈模拟队列
- 那些你不知道的项目管理细节(二)
- cocos2dx 3.0 使用ant生成apk
- 23 Out of 5 uva+回溯
- POJ 2060 Taxi Cab Scheme(匈牙利—最小路径覆盖)
- c/指针函3
- 假如你收到了一封来自Twoo的邮件...
- uboot移植中的NOR FLASH配置
- POJ 1008
- 俄罗斯方块小游戏的各类
- freemarker报错之十二
- Memcached常用命令及使用说明
- 静态路由模拟实验
- 黑马程序员---面向对象(一)