指针(三个数的交换)

#include<stdio.h>
swap(int *p1, int *p2){
        int temp;
        temp = *p1;
        *p1 = *p2;
        *p2 = temp;
}
exchange(int *ep1, int *ep2, int *ep3){
        if(*ep1<*ep2) swap(ep1,ep2);
        if(*ep1<*ep3) swap(ep1,ep3);
        if(*ep2<*ep3) swap(ep2,ep3);
}
main(){
        int a, b, c;
        int *pt1, *pt2, *pt3;
        scanf("%d,%d,%d", &a, &b, &c);
        pt1 = &a; pt2 = &b; pt3 = &c;
        exchange(pt1, pt2, pt3);
        printf("%d
%d
%d
", a, b, c);
}

 

原文地址:https://www.cnblogs.com/yuwensong/p/3884556.html