可能重复:
Malloc 或普通数组定义?
我们了解到 C 和动态变量中存在动态内存:
#include <stdio.h>
int a = 17;
int main(void)
{
int b = 18; //automatic stack memory
int * c;
c = malloc( sizeof( int ) ); //dynamic heap memory
*c = 19;
printf("a = %d at address %x\n", a, &a);
printf("b = %d at address %x\n", b, &b);
printf("c = %d at address %x\n", *c, c);
free(c);
system("PAUSE");
return 0;
}
我如何知道要使用哪种类型的内存?我什么时候需要一个或另一个?