第17周任务1-1——函数参数传递
#include <iostream> using namespace std; void jiaohuan(int x, int y);int main(void){int a,b;cin>>a>>b;if (a<b) jiaohuan(a, b); cout<<"a,b="<<a<","<<b;return 0;}void jiaohuan(int x, int y){int t;t=x; x=y; y=t;}
不能实现交换
#include <iostream> using namespace std; void jiaohuan(int *x, int *y);int main(void){int a,b;cin>>a>>b;if (a<b) jiaohuan(&a, &b); cout<<"a,b="<<a<<","<<b;return 0;}void jiaohuan(int *x, int *y){int t;t=*x; *x=*y; *y=t;}
可以实现交换
#include <iostream> using namespace std; void jiaohuan(int &x, int &y);int main(void){int a,b;cin>>a>>b;if (a<b) jiaohuan(a, b); cout<<"a,b="a<<","<<b;return 0;}void jiaohuan(int &x, int &y){int t;t=x; x=y; y=t;}
可以实现交换