面向对象程序设计上机练习四(变量引用)
2017-12-13 20:56
417 查看
面向对象程序设计上机练习四(变量引用)
Time Limit: 1000MS Memory Limit: 65536KBSubmit Statistic
Problem Description
将变量的引用作为函数形参,实现2个int型数据交换。
Input
输入2个int型整数。
Output
输出2个整数交换前后的值。
Example Input
88 66
Example Output
88 66 66 88
Hint
AuthorC++中的参数传递不可直接进行值传递,因为只是形参发生了改变,而引用可以,引用后可对其进行更改。
故方法有引用传递,指针传递。
#include<bits/stdc++.h>
using namespace std;
void Swap(int &a, int &b)
{
int t;
t = a;
a = b;
b = t;
}
int main()
{
int a, b;
cin>>a>>b;
cout<<a<<" "<<b<<endl;
Swap(a, b);
cout<<a<<" "<<b<<endl;
return 0;
}
void Swap(int *a, int *b)
{
int c =*a;
*a = *b;
*b = c;
}
相关文章推荐
- 面向对象程序设计上机练习四(变量引用)
- 面向对象程序设计上机练习四(变量引用)
- 面向对象程序设计上机练习四(变量引用)
- 面向对象程序设计上机练习四(变量引用)
- [1143]面向对象程序设计上机练习四(变量引用)
- 面向对象程序设计上机练习四(变量引用)
- [1143]面向对象程序设计上机练习四(变量引用)
- 面向对象程序设计上机练习四(变量引用)
- 【变量引用】面向对象程序设计上机练习四(变量引用)
- 面向对象程序设计上机练习四(变量引用)
- sdut 面向对象程序设计上机练习四(变量引用)
- SDUT-1143 面向对象程序设计上机练习四(变量引用)
- 面向对象程序设计上机练习四(变量引用)
- 面向对象程序设计上机练习四(变量引用)
- 面向对象程序设计上机练习四(变量引用)
- 面向对象程序设计上机练习四(变量引用)
- 面向对象程序设计上机练习四(变量引用)
- 面向对象程序设计上机练习四(变量引用)
- 面向对象程序设计上机练习四(变量引用)
- sdut 面向对象程序设计上机练习四(变量引用)