谁能帮看看问题出在哪?
#include<iostream>
using namespace std;
int swapl(int*x,int*y)
{
int*t;
t=x;
x=y;
y=t;
}
void main()
{
int a,b;
a=10;
b=20;
swapl(a,b);
cout<<"a="<<a<<endl;
cout<<"b="<<b<<endl;
}
error C2664: 'swapl' : cannot convert parameter 1 from 'int' to 'int *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.
test1.obj - 1 error(s), 0 warning(s)
[解决办法]
- C/C++ code
#include<iostream>using namespace std;int swapl(int*x,int*y){int t;t=*x;*x=*y;*y=t;}void main(){ int a,b; a=10; b=20; swapl(&a,&b); cout<<"a="<<a<<endl; cout<<"b="<<b<<endl;}
[解决办法]
int swapl(int*x,int*y)
参数是int类型的指针,所以你调用swapl(a, b);的时候参数就错了,应该是swapl(&a, &b);