题目:输入3个整数,按由小到大的顺序输出(利用指针)
#include<stdio.h>
int main()
{
void swap(int *p1,int *p2);
int *a,*b,*c;
int r,s,t;
scanf("%d",&r);
scanf("%d",&s);
scanf("%d",&t);
a=&r;
b=&s;
c=&t;
if(*a>*b) swap(a,b);
if(*a>*c) swap(a,c);
if(*b>*c) swap(b,c);
printf("%d,%d,%d",*a,*b,*c);
return 0;
}
void swap(int *p1,int *p2)
{
int temp;
temp=*p1;
*p1=*p2;
*p2=temp;
}
非技术の思索:分不太清&和*诶。报错的时候会自动把VC弹出来。唉还是太菜了哭哭。下午要把指针题刷完呀!