Is memory allocated at runtime using calloc(), malloc() and friends. It is sometimes also referred to as 'heap' memory, although it has nothing to do with the heap data-structure < sup > ref .
int * a = malloc(sizeof(int));
堆内存是持久的,直到调用 free()。换句话说,您控制变量的生命周期。
自动内存分配
这就是通常所说的“堆栈”内存,当您进入一个新的作用域时(通常是在调用堆栈上推送一个新函数时)就会分配这个内存。一旦您移出作用域,自动内存地址的值就是未定义的,它是一个 error to access them。
int a = 43;
Note that scope does not necessarily mean function. Scopes can nest within a function, and the variable will be in-scope only within the block in which it was declared. Note also that where this memory is allocated is not specified. (On a 理智 system it will be on the stack, or registers for optimisation)