| 为了更加直观的了解各个区域的内容,看以下的代码://main.cpp
#include <iostream>
using namespace std;
#include <string.h>
int a = 0;  //全局初始化区 
char *p1;  //全局未初始化区 
int main(void)
{ 
    int b;  //栈 
        char s[] = "abc";  //"abc"在常量区,s在栈上。 
        char *p2;  //栈 
        char *p3 = (char*)"123456";  //123456\0";在常量区,p3在栈上。 
        static int c = 0;  //全局(静态)初始化区 
        p1 = (char *)malloc(10); 
        p2 = (char *)malloc(20); //分配得来的 10 和 20 字节的区域就在堆区。
 
        strcpy(p1, "123456");  //123456\0放在常量区,编译器可能会将它与 p3 所指向的"123456"优化成一个地方。 
        delete p1, p2;
        return 0;
} 
 |