#include<stdio.h>
int main(){
void swap(int * p1,int * p2);//声明函数;
int a,b;
int *p1,*p2;//定义;两个整型指针变量
scanf("%d %d",&a,&b);
p1 = &a;//p1->a
p2 = &b;//p2->b
if(a<b){
swap(p1,p2);//如果a<b,调用函数swap
}
printf("max = %d,min = %d\n",a,b);//输出结果
}
void swap(int *p1,int *p2){
int temp;
temp = *p1;//使*p1和*p2的值交换,也使得a,b的值交换
*p1 = *p2;
*p2 = temp;
}
代码运行结果如下:
![](https://img-blog.csdnimg.cn/img_convert/b2de47c25cfbe17740719aae963e3470.png)