首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

哪位高手能帮看看有关问题出在哪

2012-11-05 
谁能帮看看问题出在哪?#includeiostreamusing namespace stdint swapl(int*x,int*y){int*ttxxyyt

谁能帮看看问题出在哪?
#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);

热点排行