Row & Col. Major
Row & Col. Major
Row & Col. Major
order:
Row-major order
When using row-major order, the difference between addresses of array cells in
increasing rows is larger than addresses of cells in increasing columns. For example,
consider this 2×3 array:
1 2 3
4 5 6
1 2 3 4 5 6
The difference in offset from one column to the next is 1 and from one row to the next
is 3. The linear offset from the beginning of the array to any given element A[row]
[column] can then be computed as:
Column-major order
if stored in memory with column-major order would look like the following:
1 4 2 5 3 6
With columns listed first. The memory offset could then be computed as:
where NUMROWS represents the number of rows in the array—in this case, 2.
It is possible to generalize both of these concepts to arrays with greater than two
dimensions. For higher dimension arrays, the ordering determines which dimension of
the array is listed off first. Any of the dimensions could be listed first, just the same
way that a two-dimensional array could be listed column-first or row-first. The
difference in offset between listings of that dimension would then be determined by a
product of other dimensions. It is uncommon to have any variation except ordering
dimensions first to last or last to first--equating to row-major and column-major
respectively.