#include <iostream>
using namespace std;
//void fun(int a,int b);
改为void fun(int &a ,int &b)
int main()
{
int a,b;
cin >> a;
cin >> b;
fun(a,b);
}
//void fun(int a,int b)
void fun(int &a ,int &b)
{
int t=b;
b=a;
a=t;
cout << a << " " << b << endl;
}
这段代码的目的是交换两个整数a和b的值,并在fun函数中打印出交换后的结果。然而,在当前的实现中,交换只发生在fun函数的局部作用域内,因为a和b是通过值传递的,所以main函数中的a和b的值并未改变。