Accessing a 2D (or 3D) array via a pointer

When you have an array like this:

int foo[3][2][2];

      

and you do:

int *bar = &foo[0][0][0];

      

Is this how it works?

*bar == foo[0][0][0];
*(bar+1) == foo[0][0][1];
*(bar+2) == foo[0][1][0];
*(bar+3) == foo[0][1][1];
*(bar+4) == foo[1][0][0];

      

I'm not sure and is a bit code dependent if this works.

+1


source to share


2 answers


Yes, it's called string ordering , and that's what C uses.



+4


source


On most systems, yes.



0


source







All Articles