arithmetic of 3D array pointer

hi
For 2D array we can navigate a pointer using row*no.of coloums+col arithmetic. similarly what is the arithmetic for navigating 3D dimensional array pointer.
Last edited on
The same sort of thing.

For an array of [ A ][ B ][ C ], we can index it thus:

(a * B * C) + (b * C) + (c * 1)

Notice the pattern: for each dimension, its index is multiplied by the product of the cardinality of all dimensions minor to it.

To help digest that, here's another example. Given array[ A ][ B ][ C ][ D ]:

(a * B * C * D) + (b * C * D) + (c * D) + (d * 1)

Hope this helps.
Thank u very much .
Topic archived. No new replies allowed.