1. 数组内存空间分配在栈内
栈 堆
myA[0]…myA[4]
2. int* myAPtr = new int [5]
栈 堆
myAPtr ----------> myAPtr [0]… myAPtr [4]
3. char** myAPtr=new char*[5]
for(int i=0;i<5;i++)
{
myAPtr[i]=new char[10];
}
for(int i=0;i<5;i++)
{
delete [] myAPtr[i];
}
delete[] myAPtr;
栈 堆
myAPtr ----------> myAPtr [0] ----------> myAPtr [0][0]
… …
myAPtr [4] myAPtr[0] [4]
4. 字符串"hello"分配的是只读内存
inString[0]=‘a'; //Crash! Attempt to write to read-only memory
5. char instring[] = "hello"; //Copy, 因为基于栈的变量在任何情况下都不能引用其它地方的内存
instring[0] =’a'; //Correct