所以,我有这段代码,我试图ppint
在最后释放数组。我曾尝试使用 Xcode 的泄漏来确定它是否有效,但我不太了解它。会做这个工作吗?
delete ppint[0];
delete ppint[1];
delete ppint[2];
delete ppint[3];
或者还有什么必须做的吗?
#include <iostream>
#include <string>
#include <unistd.h>
using namespace std;
int main()
{
int **ppint;
ppint = new int * [4];
for(int i = 0; i < 4; i++ ) {
ppint [i] = new int[4];
} // declares second layer of arrays
for(int i = 0, count = 0; i < 4; i++ ) {
for(int j = 0; j < 4; j++ ) {
count++;
ppint [i] [j] = count;
} //init part 2
} // init array
for(int i = 0; i < 4; i++ ) {
for(int j = 0; j < 4; j++ ) {
cout << ppint [i] [j] << endl;
} // print part 2
} //print array
}