c++通过引用实现三个数字求最大值
c++通过引用实现三个数字求最大值
发布时间:2016-12-28 来源:查字典编辑
摘要:通过这个例子来说明引用的作为函数参数的使用方法。请看代码:复制代码代码如下:#includeusingnamespacestd;intmai...

通过这个例子来说明引用的作为函数参数的使用方法。

请看代码:

复制代码 代码如下:

#include<iostream>

using namespace std;

int main(){

void max(int &, int &);//当引用作为函数参数时,声明函数的方法

int a[3];

cout<<"please input three numbers:";

cin>>a[0]>>a[1]>>a[2];

max(a[0],a[1]);//将较大值放到第一个参数中

max(a[0],a[2]);

cout<<"max:"<<a[0]<<endl;

return 0;

}

void max(int &i,int &j){

if(i<j)i=j;//注意这个函数是没有返回值的

}

c++通过引用实现三个数字求最大值1

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新C语言学习
热门C语言学习
编程开发子分类