我知道这个问题可能以前被问过,但在这种情况下我不明白:
这是我要检查的代码,我会评论它。请让我知道我错在哪里
int **A; // declaring a pointer to a pointer
A = new int*[n]; // assigning that pointer to a newly-allocated
// space (on the heap) for an array
// of [size n] of pointers to integers
for (i = 0; i < n; ++i) // looping from 0 to n-1
A[i] = new int[n]; // assigning each slot's pointer to a
// new array of size n?
for (i = 0; i < n; ++i) // loop through all the rows
for (j = 0; j < n; ++j) // loop through each column for the current row
A[i][j] = 0; // assign the value to 0
请让我知道我错在哪里。我什么都不明白,A = new int*[n];
我只是想用常识来弄清楚,但我遇到了麻烦。
谢谢!