马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
将a,b两个数按从大到小的顺序输出,为啥用第一种
指针形式可以实现,第二种形式不能实现呢。。。。#include <stdio.h>
int main()
{
void swap(int *x,int *y);
int a,b;
int *p1,*p2;
scanf("%d%d",&a,&b);
printf("a=%d,b=%d\n",a,b);
p1=&a;
p2=&b;
swap(p1,p2);
printf("%d,%d\n",a,b);
return 0;
}
void swap(int *x,int *y)
{
int t;
if(*x<*y)
{
t=*x;
*x=*y;
*y=t;
}
}
*******************************************************
*******************************************************
#include <stdio.h>
int main()
{
void swap(int x,int y);
int a,b;
scanf("%d%d",&a,&b);
printf("a=%d,b=%d\n",a,b);
swap(a,b);
printf("%d,%d\n",a,b);
return 0;
}
void swap(int x,int y)
{
int t;
if(x<y)
{
t=x;
x=y;
y=t;
}
}
|