[c++]程序的内存划分理解

时间:2014-05-05 23:48:12   收藏:0   阅读:391
bubuko.com,布布扣
#include <stdio.h>
#include <stdlib.h>

int gGlobal=100; // global 

int main(void){
        char *pLocalString1="LocalString1";
        const char *pLocalString2="LocalString2";
        static int nLocalStatic=100;
        
        int nLocal=10;
        const int nLocalConst=20;
        
        int *pNew = new int[5];
        char *pMalloc = (char*)malloc(1);
        
        
        printf("global var            0x%x\n",&gGlobal);
        printf("static var            0x%x\n",&nLocalStatic);
        printf("\n");
        printf("local var1                    0x%x\n",&pLocalString1);
        printf("local var2(const)            0x%x\n",&pLocalString2);
        
        printf("\n");
        
        printf("pNew                     0x%x\n",pNew);
        printf("pMalloc             0x%x\n",pMalloc);
        
        pLocalString1[1]=a;//error 字符常量,数据定义好后,不能在修改.该地址,在编译前已经确定好
        printf("\n");
        
        printf("local point(pNew)                     0x%x\n",&pNew);
        printf("local point(pMalloc)              0x%x\n",&pMalloc);
        printf("local point(pLocalString1)                     0x%x\n",&pLocalString1);
        printf("local point(pLocalString2)                     0x%x\n",&pLocalString2);
        printf("local point(nLocalConst)                     0x%x\n",&nLocalConst);
        printf("local point(nLocal)                     0x%x\n",&nLocal);
        
        
}
bubuko.com,布布扣

 

[c++]程序的内存划分理解,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!