Assuming you are simply talking about statically declared multi-dimensional arrays:
const int ROWS = 10;
const int COLS = 20;
const int DEPTH = 30;
int array[ROWS][COLS][DEPTH]; // statically allocated array
int i = 0;
for (int row = 0; row < ROWS; ++row)
{
for (int col = 0; col < COLS; ++col)
{
for (int depth = 0; depth < DEPTH; ++depth)
{
*(*(*(array + row) + col) + depth) = i++; // do whatever with it
// is equivalent to array[row][col][depth] = i++;
}
}
}
If you need more levels, you just keep adding levels of pointer indirection.
Alternatively:
const int ROWS = 5;
const int COLS = 6;
const int DEPTH = 3;
int array[ROWS][COLS][DEPTH]; // statically allocated array
int* p = &array[0][0][0];
int c = 0;
for (int i = 0; i < ROWS * COLS * DEPTH; ++i, p++)
{
*p = c++;
}
Since a statically declared array is going to be contiguous in memory, with the first element (array[0][0][0]) starting at the base address (&array), this works.
Declaring a multi-dimensional array dynamically is going to be a pointer to an array of pointers to (etc) to pointers to an array of object_type. You can simplify that by using std::vector or std::array (if you know the size at compile time).
Not that these use pointers to iterate (at least not directly), but
Vector/Array
std::vector<std::vector<std::vector<int> > > array;
// or
//std::array<std::array<std::array<int, DEPTH>, COLS>, ROWS> array; // with some slight modifications
// fill in the vectors/arrays however you want
std::for_each(array.begin(), array.end(), [](const std::vector<std::vector<int> >& v)
{
std::for_each(v.begin(), v.end(), [](const std::vector<int>& a)
{
std::for_each(a.begin(), a.end(), [](int i)
{
std::cout << i << endl;
});
});
});
arrwas actually declared.