面向对象程序设计上机练习四(变量引用)

来源:互联网 发布:淘宝天天特价首页 编辑:程序博客网 时间:2024/05/22 03:16

Problem Description
将变量的引用作为函数形参,实现2个int型数据交换。
Input
输入2个int型整数。
Output
输出2个整数交换前后的值。
Example Input
88 66
Example Output
88 66
66 88

关于&作函数形参,不理解的话看:http://blog.csdn.net/gx17864373822/article/details/78347300

#include <iostream>using namespace std;void change(int &a, int &b){    int temp;    temp=a;    a=b;    b=temp;    cout<<a<<" "<<b<<endl;}int main(){    int a,b;    cin>>a>>b;    cout<<a<<" "<<b<<endl;    change(a,b);    return 0;}
原创粉丝点击