How are the elements of a 2D array are stored in the memory?

Category: Data StructureHow are the elements of a 2D array are stored in the memory?
1 Answers
Editor">Editor Staff answered 2 years ago

There are two techniques by using which, the elements of a 2D array can be stored in the memory.
Row-Major Order: In row-major ordering, all the rows of the 2D array are stored into the memory contiguously. First, the 1st row of the array is stored into the memory completely, then the 2nd row of the array is stored into the memory completely and so on till the last row.
Column-Major Order: In column-major ordering, all the columns of the 2D array are stored into the memory contiguously. first, the 1st column of the array is stored into the memory completely, then the 2nd row of the array is stored into the memory completely and so on till the last column of the array.