Row Major Vs Column Major Order: 2D arrays access in programming languages
The way you access the array affects performance.

It depends on how the matrix is represented and stored in memory.  Often a matrix is stored in row-major order, so that consecutive elements of a row are contiguous in memory.  Reading memory in contiguous locations is faster than jumping around among locations.  As a result, if the matrix is stored in row-major order, then iterating through its elements sequentially in row-major order may be faster than iterating through its elements in column-major order.

Of course, if the matrix is stored in column-major order, the reverse will be true.

See https://en.wikipedia.org/wiki/Row-_and_column-major_order for more on the subject.