64,654
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
#include <windows.h>
int & Reference(){
int m;
int &n=m;
return n;
}
int Global; // 全局变量
int main(int argc, char * argv[]){
int Stack; // 存在栈空间
static int Static; // 静态/全局空间
int *PToGlobal = &Global + 16; // 指向全局/静态内存区域未分配初始化的地址;
const int ConstVariable =5; // const变量也存放在栈空间
char * Constant = "abcd"; // 指向常量空间
int & (*Code)() = Reference; // 代码空间地址
int * Heap = new int[10];
printf("栈空间 Stack :0x%p\n", &Stack);
printf("堆空间 Heap :0x%p\n", Heap);
// 静态全局区域的值全部为0,解释为什么不用static值初始化就自动为0
printf("全局/静态 Global :0x%p, Static:0x%p, PToGlobal地址:0x%p, *PToGlobal:%d\n", &Global, &Static, PToGlobal, *PToGlobal);
printf("常量 Constant:0x%p, ConstVariable:0x%p\n", Constant, &ConstVariable);
printf("代码区 Code :0x%p\n", Code);
delete []Heap;
system("pause");
return 0;
}