指针函数交换两个数

Posted deaky

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了指针函数交换两个数相关的知识,希望对你有一定的参考价值。

#include <stdio.h>

void swap(int  *x,int *y);

int main()

{

       int m,n;

       scanf("%d%d",&m,&n);

       printf("before swap:m=%d n=%d\n",m,n);

       swap(&m,&n);                                                  //注意引用函数,两个值前用地址符。

       printf("after swap:m=%d n=%d\n",m,n);

       return 0;

}

void swap(int  *x,int *y)

{

    int temp;

    temp=*x;

    *x=*y;

    *y=temp;

}

    

    

以上是关于指针函数交换两个数的主要内容,如果未能解决你的问题,请参考以下文章