#include<iostream>
using namespace std;
void swap(int *a,int *b)
{
int *temp;
temp=a;
a=b;
b=temp;
}
void main()
{
int a,b;
cin>>a>>b;
swap(a,b);
cout<<a<<" "<<b<<endl;
}
可以通过啊,swap(a,b);可以输出交换后的知,但swap(&a, &b)这输出后没变化???
不信你试试.
hello.c: 在函数‘main’中:
hello.c:15: 警告:传递‘swap’的第 1 个参数时将整数赋给指针,未作类型转换
hello.c:4: 附注:需要类型‘int *’,但实参的类型为‘int’
hello.c: 在函数‘main’中:
hello.c:15: 警告:传递‘swap’的第 1 个参数时将整数赋给指针,未作类型转换
hello.c:4: 附注:需要类型‘int *’,但实参的类型为‘int’