当前位置: 代码迷 >> C语言 >> 为什么我不能实现两个参数交换啊??
  详细解决方案

为什么我不能实现两个参数交换啊??

热度:99   发布时间:2007-09-17 20:09:25.0
回复:(神vLinux飘飘)[CODE]#include
你这个写的很新啊!!偶从来没见过啊!!牛
----------------解决方案--------------------------------------------------------
回复:(iaw398492065)还要说下,你的编程风格要简洁...
哦~~~谢谢高手指点~~~
----------------解决方案--------------------------------------------------------
回复:(死了都要C)形参和实参````采用的是值传递```...
我很喜欢你写的这个程序~~~我要保存下来
----------------解决方案--------------------------------------------------------

谢谢1楼和10楼的达人~~呵呵


----------------解决方案--------------------------------------------------------
回复:(死了都要C)形参和实参````采用的是值传递```...

对了~~~哪个void swap写错了~~~应该是int swap,不然不能运行啊!!


----------------解决方案--------------------------------------------------------
指针,引用
----------------解决方案--------------------------------------------------------
10楼的我的机子运行不了啊 怎么回事啊…………
----------------解决方案--------------------------------------------------------

哈哈....
又学到了.


----------------解决方案--------------------------------------------------------
#include <stdio.h>
int swap(int *p,int *q)
{
int t;
t=0;
t=*p;
*p=*q;
*q=t;
}
int main(void)
{
int a , b;
a=100;
b=200;
void swap(a,b);
printf("%d\t%d\n",a,b);
return 0;
getchar ();
} 不知道对不对了 在网吧了 没编译
还有不调用函数也行吧 ?


----------------解决方案--------------------------------------------------------
swap函数没返回值,主函数都return了后面的getchar没用
#include <stdio.h>
void swap(int *p,int *q)
{
int t;
t=0;
t=*p;
*p=*q;
*q=t;
}
int main(void)
{
int a , b;
a=100;
b=200;
swap(&a,&b);
printf("%d\t%d\n",a,b);
return 0;
// getchar ();
}
----------------解决方案--------------------------------------------------------