#include "stdafx.h"
#include "iostream"
void sort(int **p1,int **p2);
int _tmain(int argc, _TCHAR* argv[])
{
    int a=0,b=0;
    scanf("%d %d",&a,&b);
    int *p1=&a,*p2=&b,*t;
    sort(&p1,&p2);//想在sort中改变指针的指向,应传指针的地址,即地址的地址

    printf("%d %d\n",a,b);
    printf("%d %d",*p1,*p2);

    system("pause");
    return 0;
}
void sort(int **p1,int **p2)
{
    int *t;
    if(**p1<**p2)
    {
        t=*p1;//由于此时p1类型为int **p1,所以此时*p1是指针p1的地址,而非内容
        *p1=*p2;
        *p2=t;
    }
}

所以结果为:

78 90

78 90

90 78                  

相关文章:

  • 2022-01-10
  • 2021-11-18
  • 2021-09-23
  • 2022-12-23
  • 2021-11-18
  • 2021-08-27
  • 2021-06-24
  • 2021-08-07
猜你喜欢
  • 2021-08-31
  • 2021-11-11
  • 2022-02-07
  • 2022-12-23
  • 2022-12-23
  • 2021-08-10
  • 2021-08-01
相关资源
相似解决方案