#include<stdio.h>
void swap(int *a,int *b){
    int temp;
    temp=*a;
    *a=*b;
    *b=temp;
}
void main(){
    int a,b,*m,*n;
    a=4;
    b=5;
    m=&a;
    n=&b;
    printf("a=%d,b=%d\n",a,b);
    swap(m,n);
    printf("a=%d,b=%d\n",a,b);

}

备注:就是在swap里面temp这个额外空间不能写成指针变量。。必须写成整形变量。

 

相关文章:

  • 2022-12-23
  • 2021-07-13
  • 2021-09-16
  • 2022-12-23
  • 2021-12-11
  • 2022-12-23
  • 2021-09-19
  • 2021-09-03
猜你喜欢
  • 2022-01-02
  • 2022-12-23
  • 2022-12-23
  • 2021-12-30
  • 2022-12-23
  • 2021-07-09
  • 2022-12-23
相关资源
相似解决方案