全局区存放了全局变量,静态变量,字符串常量,const修饰的全局变量
string 字符串内容不在全局区, const修饰的局部变量也不再全局区
代码验证如下
//全局区 存放全局变量,静态变量,常量(字符串常量和const修饰的变量) //该区域的生死由系统控制,该内存在程序结束由编译器释放 #include<iostream> using namespace std; const int a = 10; int quanjuV = 15; //创建全局变量 int main() { int jubuVerb = 10; //创建一个局部变量 int jbVerb = 12; //创建静态变量 static int staV = 10; //字符串常量 cout << "字符串地址" << &"zifu" <<endl; //const修饰局部变量 成局部常量 const int ju = 10; cout << "const 修饰的局部变量地址" << &ju <<endl; cout << "const修饰的全局变量地址" << &a <<endl; cout << "static修饰静态变量地址" << &staV << endl; cout << "全局变量地址" << &quanjuV << endl; cout << "局部变量的地址" << &jubuVerb << endl; cout << "局部变量的地址" << &jbVerb << endl; //输出结果 /* 字符串地址0x44200b
const 修饰的局部变量地址0x66ff1c
const修饰的全局变量地址0x44207c
static修饰静态变量地址0x441004
全局变量地址0x441000
局部变量的地址0x66ff24
局部变量的地址0x66ff20 */ system("pause"); return 0; }
原文:https://www.cnblogs.com/gjbhpu0308/p/12467942.html