?
So nach 2 Stunden pröbeln etc. habe ich die Lösung - so glaube ich - gefunden..
wäre froh, wenn jemand bestätigen könnte, dass dies so gemeint war....
// Program: threedim_array.C
// iterate over a multidimensional array
#include <iostream>
int main()
{
int a[4][2][3] =
{ // the 4 elements of a:
{ // the 2 elements of a[0]:
{2, 4, 5}, // the three elements of a[0][0]
{4, 6, 7} // the three elements of a[0][1]
},
{ // the 2 elements of a[1]:
{1, 5, 9}, // the three elements of a[1][0]
{4, 6, 1} // the three elements of a[1][1]
},
{ // the 2 elements of a[2]:
{5, 9, 0}, // the three elements of a[2][0]
{1, 5, 3} // the three elements of a[2][1]
},
{ // the 2 elements of a[3]:
{6, 7, 7}, // the three elements of a[3][0]
{7, 8, 5} // the three elements of a[3][1]
}
};
// Output: The above array using (damn) pointer arithmetic
// Firstly, we initalize a pointer which points
// to the first element of a. (That is a to say)
int (*p)[2][3] = a;
// Secondly, we initialize a pointer which points
// to the first element of the first element of a.
// In random acces we would talk \1: a[0][0]
int (*q)[3] = *p;
// Now it is getting difficult
// Finally we initialize a pointer of the first element of
// the element of the element of a.
// These is equal to the random access' a[0][0][0]
int (*r) = *q;
for (int i=0,j,k; i<4; i++) {
(p)++;
for(j=0;j<2;j++) {
(q)++;
for(k=0;k<3;++k){
std::cout<< *r << " "; // Outputs every number one by one on one line (if only this std::cout is used)
(r)++;
}
}
}
return 0;
}
Damian