标题:地址传递,两结果怎么不同?
取消只看楼主
曹岂源
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2015-3-14
结帖率:50%
已结贴  问题点数:20 回复次数:1 
地址传递,两结果怎么不同?
#include"stdio.h"
void main()

{   
    void swap(int *x,int *y);
    int a=10,b=20;
    printf("a=%d,b=%d\n",a,b);
    swap(&a,&b);
    printf("after swap\ta=%d,b=%d\n",a,b);
}

void swap(int *x,int *y)
{
    int t;
    t=*x;
    *x=*y;
    *y=t;
    printf("in swap x=%d,y=%d\n",*x,*y);
}
a=10 b=20
x=20 y=10
a=20 b=10
#include"stdio.h"
void main()

{   
    void swap(int *x,int *y);
    int a=10,b=20;
    printf("a=%d,b=%d\n",a,b);
    swap(&a,&b);
    printf("after swap\ta=%d,b=%d\n",a,b);
}

void swap(int *x,int *y)
{
    int *t;
    t=x;
    x=y;
    y=t;
    printf("in swap x=%d,y=%d\n",*x,*y);
}
a=10 b=20
x=20 y=10
a=10 b=20
搜索更多相关主题的帖子: include 
2015-03-17 21:35
曹岂源
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2015-3-14
得分:0 
求大神帮助
2015-03-17 21:42



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-442768-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.226779 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved