#include
using namespace std;
int main()
{
void swap1(int* a,int* b);
void swap2(int &a, int &b);
int a=6,b=92,t=0;
swap1(&a,&b);
swap2(a,b);
return 0;
}
void swap1(int* a,int* b)
{
int tem;
tem=*a;
*a=*b;
*b=tem;
cout << "a is :" << *a << " " << "b is :" << *b <
}
void swap2(int &a, int &b)
{
int tem1;
tem1=a;
a=b;
b=tem1;
cout << "a is :" << a << " " << "b is :" << b <
}
指针作形参a,b的值可以对调,引用作形参为什么a,b的值无法对调。
求指点。
那咋知道没有对调啊,调用swap2时,swap1已经把a,b交换过来了,swap2应该是把a,b值又还原了啊
不知道你这个问题是否已经解决, 如果还没有解决的话: