指针练习--变量交换

#include <iostream>
using namespace std;
int main()
{
    int *p1,*p2,*p;
    int a,b;
    cin>>a>>b;
    p1=&a;
    p2=&b;
    if(a>b)
    {
        /*
        int c;
        c=*p1;
        *p1=*p2;
        *p2=c;*/
        p=p1;
        p1=p2;
        p2=p;
    }
    cout<<"min:"<<*p1<<endl;
    cout<<"max:"<<*p2<<endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/xjp_xujiping/article/details/79595947