第18、19周 项目2 引用作形参
来源:互联网 发布:ai传淘宝切割照片 编辑:程序博客网 时间:2024/05/14 14:40
//利用引用类型做函数参数#include <iostream>using namespace std;void sort(int &x,int &y,int &z);int main(){ int a,b,c; cin>>a>>b>>c; sort(a,b,c); cout<<a<<" "<<b<<" "<<c<<" "; return 0;}void sort(int &x,int &y,int &z){ int t; if(x<y) { t=x; x=y; y=t; } if(y<z) { t=y; y=z; z=t; } if(x<y) { t=x; x=y; y=t; }}
//利用指针传地址值的方法#include <iostream>using namespace std;void sort(int *x,int *y,int *z);int main(){ int a,b,c; cin>>a>>b>>c; sort(&a,&b,&c); cout<<a<<" "<<b<<" "<<c<<" "; return 0;}void sort(int *x,int *y,int *z){ int t; if(*x<*y) { t=*x; *x=*y; *y=t; } if(*y<*z) { t=*y; *y=*z; *z=t; } if(*x<*y) { t=*x; *x=*y; *y=t; }}
总结:复习一下关于指针的知识,定义变量时*是指针的标志,不是取值符号,定义变量时&是引用类型的标志;而在运算过程中*是取该地址储存的值,&是取该变量的地址(假如该变量是指针变量,取的仍是保存这个变量的地址值,而不是这个指针所储存的地址值),搞清楚这些,指针的基本运用应该没问题,指针数组的内容反倒不必涉及到这么多的单个变量的地址、取值、取地址的操作,指针数组在前面有所博文,可供我自己参考。
0 0
- 第18、19周 项目2 引用作形参
- 第17周项目2-引用作形参
- 第17周 项目2-作形参(引用)
- 第17周项目2-引用作形参
- 第17周项目2-引用作形参
- 第17周【项目 2-引用作形参】
- 第17周项目2引用作形参
- 第17周项目2-引用作形参
- 第17周 项目2 引用作形参
- 第17周项目2(2)-引用作形参
- 第17周项目2(1)-引用作形参
- 第17周项目2—引用作形参
- 第17周项目2-引用做形参
- 第17周项目2 引用做行参
- 第17周 项目2-引用作参数(2)
- 第17周 项目2-引用作参数(2)
- 第17周项目2-引用做形参(2)
- 第17周 项目2-引用作参数(1)
- ubuntu下eclipse pydev 离线 环境搭建 及相关问题解决
- Android中常用颜色
- 影响Java EE性能的十大问题
- C++之父:C++ 的五个普遍误解(3)
- leetcode9:Next Permutation
- 第18、19周 项目2 引用作形参
- OpenCV 生成 伪彩色图像 pseudo color image 易用colorbar 调节
- Eigen C++ 模板库,用来矩阵向量的线性操作
- 实现和调试 Malloc、Free、Calloc 和 Realloc 的快速教程
- Eclipse中常用快捷键
- cannot delete name node is in safe mode
- Kalman滤波器从原理到实现
- 编写高效的C程序与C代码优化
- ubuntu12.04安装python3.4