首页 > 其他 > 详细

互换两个变量的值

时间:2020-11-18 10:40:57      阅读:23      评论:0      收藏:0      [点我收藏+]
#include<stdio.h>
void huhuan_1(int,int);
void huhuan_2(int *,int *);
void huhuan_3(int *,int *);
int main(void)
{
    int a=3,b=5;
    //huhuan_1(a,b);
    //huhuan_2(&a,&b);
    huhuan_3(&a,&b);
    printf("a=%d,b=%d\n",a,b);
}
void huhuan_1(int a,int b)
{
    int t;
    t=a;
    a=b;
    b=t;
}
void huhuan_2(int * p,int * q)
{
    int * t;
    t=p;
    p=q;
    q=t;
}
void huhuan_3(int * p,int * q)
{
    int t;//如果要互换*p和*q,则t必须定义成int类型
    t=*p;//p是int *,*p是int类型
    *p=*q;
    *q=t;
}

 

互换两个变量的值

原文:https://www.cnblogs.com/ajiaoa/p/13998433.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!