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

来源:互联网 发布:淘宝旺铺有什么功能 编辑:程序博客网 时间:2024/05/22 01:30

Problem Description

将变量的引用作为函数形参,实现2个int型数据交换。

Input

输入2个int型整数。
Output

输出2个整数交换前后的值。

Example Input

88 66

Example Output

88 66
66 88

code

#include <iostream>using namespace std;void change(int c, int d){    cout << c << " " << d << endl;    int t;    t = c;    c = d;    d = t;    cout << c << " " << d << endl;}int main(){    int a,b;    //变量引用    int &x = a;    int &y = b;    cin >> a >> b;    change(x,y);    return 0;}
阅读全文
0 0