Computer Applications
How are two-dimensional arrays represented in memory ?
Java Arrays
9 Likes
Answer
Two-dimensional arrays are stored in a row-column matrix, where the first index indicates the row and the second indicates the column.
For example, if we have declared an array pay as follows:short[][] pay = new short[5][7];
it will be having 5 x 7 = 35 elements which will be represented in memory as shown below :

The amount of storage required to hold a two-dimensional array is also dependent upon its base type, number of rows and number of columns. The formula to calculate total number of bytes required by a two-dimensional array is given below :
total bytes = number-of-rows x number-of-columns x size-of-base-type
Here, the array pay[][] will require 5 x 7 x 2 = 70 bytes of memory space, as the size of a byte type element is 2 bytes.
Answered By
7 Likes
Related Questions
How does the amount of storage (in bytes) depend upon type and size of an array? Explain with the help of an example.
What do you understand by two-dimensional arrays ? State some situations that can be easily represented by two-dimensional arrays.
Suppose A, B, C are arrays of integers of sizes m, n, m + n respectively. Give a program to produce a third array C, containing all the data of array A and B.
Write a short program that doubles every element of an array A[4][4].