Example of row major order


Now that we know how the row-major order is used to serialize a multidimensional array into a single-dimensional/linear sequence of data, we can use a three-dimensional array as an example to visualize this serialization and understand what happens under the hood when we try to access an element in a multidimensional array.

Let us consider an example of a three-dimensional (2x2x3) integer array where D3 = 2, D2 = 2 and D1 = 3 (using the higher to lower dimension convention from the previous lessons). The logical representation of the three-dimensional array is given below.

Logical representation of a three-dimensional array where D3=2, D2=2 and D1=3

Liking the course? Check our discounted plans to continue learning.