内存分区:
1、堆(malloc(C语言)或new(C++));
2、栈(编译器自动分配);
3、全局(静态)存储区:DATA(全局初始化区)和BSS(全局未初始化区)
4、文字常量区:
5、程序代码区:
int k=1;//全局存储区(DATA段)
void main()//程序代码区
{
int i=1;//栈
static int m;// 全局存储区(BSS段)
char *n="hello"// n位于栈上,内容是地址, "hello"位于文字常量区,此时"hello"在内存中只有一份拷贝
char a[]="hello"// a位于栈上,是一个有6个元素的数组,并将"hello"拷贝到它所占内存中,此时"hello"有两份拷贝
char *j;//栈
j=(char*)malloc(2);// 堆区
}