SDUT-1143 面向对象程序设计上机练习四(变量引用)
2017-11-12 21:23
489 查看
面向对象程序设计上机练习四(变量引用)
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
Author
zlh引用是一个隐性指针,引用值引自所指向的实体
//传递变量的指针
#include <iostream> using namespace std; void Swap(int *a,int *b) { int 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; }
//传递变量的别名 #include <iostream> using namespace std; void Swap(int &a,int &b) { int 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; }
相关文章推荐
- sdut 面向对象程序设计上机练习四(变量引用)
- sdut 面向对象程序设计上机练习四(变量引用)
- sdut 面向对象程序设计上机练习四(变量引用)
- [1143]面向对象程序设计上机练习四(变量引用)
- [1143]面向对象程序设计上机练习四(变量引用)
- 1143-面向对象程序设计上机练习四(变量引用)
- 面向对象程序设计上机练习四(变量引用)
- 面向对象程序设计上机练习四(变量引用)
- 面向对象程序设计上机练习四(变量引用)
- 面向对象程序设计上机练习四(变量引用)
- 面向对象程序设计上机练习四(变量引用)
- 【变量引用】面向对象程序设计上机练习四(变量引用)
- 面向对象程序设计上机练习四(变量引用)
- 面向对象程序设计上机练习四(变量引用)
- 面向对象程序设计上机练习四(变量引用)
- 面向对象程序设计上机练习四(变量引用)
- 面向对象程序设计上机练习四(变量引用)
- 面向对象程序设计上机练习四(变量引用)
- 面向对象程序设计上机练习四(变量引用)
- 面向对象程序设计上机练习四(变量引用)