KnowledgeBoat Logo
LoginJOIN NOW

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 :

How are two-dimensional arrays represented in memory? Arrays, Sumita Arora Computer Applications Solutions ICSE Class 10

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