qiangua
#include<stdio.h>

void swap(int *a,int *b);
void dummy_swap(int *a,int *b);
int main()
{
    int c=3,d=76;
    swap(&c,&d);
    printf("c=%d,d=%d\n",c,d);
    dummy_swap(&c,&d);
    printf("c=%d,d=%d\n",c,d);
    swap(&c,&d);
    printf("c=%d,d=%d\n",c,d);
    printf("-----------------分割线-----------------\n");
    return 0;
}
void swap(int *a,int *b)
{
    int temp=0;
    //更改指针指向的值
    temp=*a;
    *a=*b;
    *b=temp;
}
//不要妄图使用下面的做法
void dummy_swap(int *a,int *b)
{
    int *temp=NULL;
    //更改指针值
    temp=a;
    a=b;
    b=temp;
}

分类:

技术点:

相关文章:

  • 2021-06-20
  • 2021-11-23
  • 2022-02-02
  • 2022-01-10
  • 2022-12-23
  • 2022-12-23
  • 2021-05-24
  • 2021-11-16
猜你喜欢
  • 2021-11-18
  • 2021-11-18
  • 2021-11-18
  • 2021-11-18
  • 2021-11-18
  • 2021-08-14
  • 2021-11-25
相关资源
相似解决方案