C 函数指针 参数传递
来源:互联网 发布:巨型海报打印软件 编辑:程序博客网 时间:2024/05/21 17:21
代码
#include<iostream>using namespace std;// 函数指针void (*pfun)(int *);// 重定义函数指针typedef void (*pFun)(int &);// 指针函数int * sub(int *a, int *b){ int * s; int c; c = (*a)+(*b); s = &c; return s;}void test(int a){ a += 1;}void test_1(int * a){ *a = *a+1;}void test_2(int &a){ a = a+1;}void test_3(pFun pfun, int &a){ pfun(a);}int main(void){ int *p; int a = 3, b = 4; p = sub(&a, &b); cout<<"a+b="<<*p<<endl; test(a); cout<<"a = "<<a<<endl; test_1(&a); cout<<"a = "<<a<<endl; test_2(a); cout<<"a = "<<a<<endl; test_3(test_2, a); cout<<"a = "<<a<<endl; pfun = test_1; (*pfun)(&a); cout<<"a = "<<a; return 0;}
运行结果
a+b=7
a = 3
a = 4
a = 5
a = 6
a = 7
0 0
- C 函数指针 参数传递
- C中函数传递参数原理:值传递, 指针传递?
- C中函数传递参数原理:值传递, 指针传递?
- C 函数传递指针参数注意事项
- [C++]关于指针作为函数参数传递
- [C++]关于指针作为函数参数传递
- c指针与函数参数传递方式
- 函数参数传递->指针
- 函数参数传递指针
- C指针参数传递
- C或C++中函数的参数传递包括:值传递、指针传递、引用传递
- C或C++中函数的参数传递——值传递、指针传递、引用传递
- c语言函数用指针传递参数问题
- C\C++函数间指针参数的传递
- C语言中函数和指针的参数传递
- c语言 函数 用指针传递参数 问题
- C语言函数传递指针参数的问题
- C语言函数传递指针参数的问题
- HDU1599
- Spring中事务的传播行为
- java连接redis
- 剑指offer 构建乘积数组
- 关于错误和异常处理(持续更新)
- C 函数指针 参数传递
- typedef用法总结笔记
- 170419 汇编-cmp指令
- bzoj 4402 Claris的剑
- 全球各国as自治系统总数排名、全球自治系统总数排名
- [学习笔记07]JS中的继承
- todo
- 【IMWeb训练营作业】vue-Todolist
- 五层协议及每层主要功能