标题:变量的值和变量在内存中的地址的关系?求解
取消只看楼主
peng880610
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:128
专家分:123
注 册:2017-3-29
结帖率:100%
已结贴  问题点数:18 回复次数:0 
变量的值和变量在内存中的地址的关系?求解
#include <stdio.h>
#include <conio.h>
void swap2Variable(int* a,int* b)
{
    printf("a在内存中的地址为%p,b在内存中的地址为%p\n",&a,&b);
    printf("a的值为%p,b的值为%p\n",a,b);
    int temp;
    temp=*a;
    *a=*b;
    *b=temp;
}

int main()
{
    int num1=3,num2=5;
    printf("num1在内存中的地址为%p,num2在内存中的地址为%p\n",&num1,&num2);

    int* pnum1=&num1;
    int* pnum2=&num2;
    printf("pnum1在内存中的地址为%p,num2在内存中的地址为%p\n",&pnum1,&pnum2);
    printf("pnum1的值为%p,num2的值为%p\n",pnum1,pnum2);
    swap2Variable(pnum1,pnum2);
    printf("num1=%d,num2=%d",num1,num2);
    getch();
    return 0;

}
上述代码运行结果如下:

问题了来了,这个pnum1的值和pnum1在内存的地址是怎么样的关系?求大神帮忙指点下。。。
搜索更多相关主题的帖子: include 
2017-05-20 13:26



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




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

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