這兩種釋放二維數組的方法相似嗎?刪除二維數組C++
int** M = new int*[5];
for (int i = 0; i < 5; ++i)
M[i] = new int[3];
for (int i = 0; i < 5; ++i) {
for (int j = 0; j < 3; ++j) {
M[i][j] = i + j;
}
}
刪除我:
for (int i = 0; i < 5; ++i)
delete [] M[i];
delete [] M;
和刪除II:
delete [] *M;
delete [] M;
是這兩個代碼相同呢?
發生了什麼事?你爲什麼不做廣告? – Ben
爲什麼不使用'的std :: vectors'?節省了很多麻煩 –
的@EdHeal最好的辦法是使用智能指針。但我感興趣的指針和數組的工作現在 – Zeis45