简单指针问题,谢谢回复!!

来源:百度知道 编辑:UC知道 时间:2024/05/31 09:51:28
swap(int x,int y)
{ int t;
t=x; x=y; y=t;
return(x,y);
}
main()
{ int a,b;
int *pointer_1,*pointer_2;
scanf("%d,%d",&a,&b);
pointer_1=&a; pointer_2=&b;
if(a<b) swap(*pointer_1,*pointer_2);
printf("\n%d,%d\n",a,b);

}
为什么没有从大到小输出啊、?

#include <stdio.h>

void swap(int &x,int &y) //如果你想引用的话,应该这样
{
int t;
t=x; x=y; y=t;
}

void main()
{
int a,b;
int *pointer_1,*pointer_2;
scanf("%d,%d",&a,&b);
pointer_1=&a;
pointer_2=&b;
if(a<b)
swap(*pointer_1, *pointer_2);
printf("\n%d,%d\n",a,b);

}

有return(x,y)这种方法吗,不是只能返回一个参数吗,要返回两个参数的话就得用指针或者结构体,你可以用引用,但要用引用的话就得用楼上的方法....不过好像你写的C程序,C不能用引用,看来还是得用指针,或者其它方法.....