If why we use 2d array to store data even we can store it in 1d array?

We can store data in both int a[1][2] and int a[2] so why 2d?


3/27/2020 12:21:35 PM

Gaurav Rawat

3 Answers

New Answer


It is useful if you want to compute data in tabular form and useful in performing operations related to matrices


For example, it would be somewhat difficult to display the points with Cartesian coordinates in a simple array.


A two dimensional array is just an abstraction for convenience. In reality it is just a continuous sequence of bytes in memory. In terms of memory usage there is no difference between a 4x4 two dimensional array of integers and a one dimensional array of 16 integers. Behind the scenes the runtime libraries are doing the multiplication and addition of the start address, element size, row and column numbers etc. to calculate a specific elements address.