第四课 内存图
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/eeb7cc2d352e57a231e5ca6a8ab272f0" alt="" /></p>
<hr />
<pre><code class="language-cpp">int globalVar = 1; //全局、局部变量存储在数据段
static int staticGlobalVar = 1;
void Test()
{
static int staticVar = 1;
int localVar = 1;
int num1[10] = { 1, 2, 3, 4 };
char char2[] = "abcd";
char* pChar3 = "abcd";
int* ptr1 = (int*)malloc(sizeof (int)* 4);
int* ptr2 = (int*)calloc(4, sizeof(int));
int* ptr3 = (int*)realloc(ptr2, sizeof(int)* 4);
free(ptr1);
free(ptr3);
}</code></pre>
<p>上述代码分别存储在什么地方呢?思考一下吧 ヾ(✿゚▽゚)ノ
如下是内存区域划分图,跟刚才你想的一样吗 ?????</p>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/1683cfd8e07a27567380ad93f1f902c8" alt="" /></p>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/03d0028fdf46253076bd89fb15d4f147" alt="" /></p>