我正在阅读"C Primer Plus"这本书并遇到一个问题,以了解记忆的区域.在书中,它指出:
通常,程序对静态对象,自动对象和动态分配的对象使用不同的内存区域.清单12.15说明了这一点.
// where.c -- where's the memory?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int static_store = 30;
const char * pcg = "String Literal";
int main(void)
{
int auto_store = 40;
char auto_string[] = "Auto char Array";
int *pi;
char *pcl;
pi = (int *) malloc(sizeof(int));
*pi = 35;
pcl = (char *) malloc(strlen("Dynamic String") + 1);
strcpy(pcl, "Dynamic String");
printf("static_store: %d at %p\n", static_store, &static_store);
printf(" auto_store: %d at %p\n", auto_store, &auto_store);
printf(" *pi: …Run Code Online (Sandbox Code Playgroud) c ×1