c++新手求助
描述填空,使得程序输出结果是:
5,3
#include <iostream>
using namespace std;
void swap(
// 在此处补充你的代码
)
{
int * tmp = a;
a = b;
b = tmp;
}
int main()
{
int a = 3,b = 5;
int * pa = & a;
int * pb = & b;
swap(pa,pb);
cout << *pa << "," << * pb;
return 0;
}
为什么在swap中输入int *a,int *b,实参不能交换? 这个swap中应该怎么填? #include <iostream>
using namespace std;
void swap(
// 在此处补充你的代码
int *&a, int *&b
)
{
int * tmp = a;
a = b;
b = tmp;
}
int main()
{
int a = 3,b = 5;
int * pa = & a;
int * pb = & b;
swap(pa,pb);
cout << *pa << "," << * pb;
return 0;
}
页:
[1]