for (int i = 0; i < ROW; i++)
{
for (int j = 0; j < COL; j++)
{
// typical array element is *(ary[i]+j));
// where ary is the array
}
}
//and don't forget to clean up before exit ...
for (i = 0; i < ROW; i++) {
delete(ary[i]);
delete [] ary;
why this because in a pointer of pointer representation of 2D array we first allocate memory for each row starting from the first element; and then, for each row, starting from the first element we allocate memory according to the size of the columns
for (int i = 0; i < firstDimensionSize; i++)
{
for (int j = 0; j < secondDimensionSize; j++)
{
array[i][j] // i will loop through the rows and j will loop through the columns.
}
}
You will need to expand on the code in the second for loop, but it is the basic idea.
int** ary;
ary = new(int* [ROW]);
for(int i = 0; i < ROW; i++)
{
ary[i] = newint[COL];
}
//to use the array:
for (int i = 0; i < ROW; ++i) { // for each row
for (int j = 0; j < COL; ++j) { // for each column
ary[i][j] = 1;
}
}
//finally, to delete before exit:
for (int i = 0; i < ROW; i++) {
delete[] ary[i];
}
delete[] ary;