Your comments suggest a 3D array rather than a 2D. So if we remove the
do {} while (a < 64);
block we could fill a 100 x 80 element 2D array thus:
int rows = 100; int cols = 80;
int **ptr;
ptr = (int**)calloc(rows, sizeof(int*));
int a = 0;
for (int i=0; i<rows;>{
ptr[i] = (int*)calloc(cols, sizeof(int));
for (int j = 0; j<cols;> {
ptr[i][j] = a++;
cout << "ptr[" << i << "][" << j << "] = " << a << endl;
}
}
Note that I used the
calloc()
function as it makes more sense when allocating anything other than an array of bytes.
The arrays can be freed when the program no longer needs them, and would be in the reverse order of the
malloc()
calls; I leave that as an exercise for you.