English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Define the term array. How are two-dimensional arrays represented in memory? Emplain how address of an element is calculated in a two dimensional array.

2007-08-10 01:32:50 · 4 answers · asked by Anonymous in Computers & Internet Programming & Design

4 answers

The standard way: if you have an array that is x by y (a[x][y]), it is stored as a straight list of x*y elements. To find a[i][j], you take the "i*y + j"th element. Each time you increment the row (i), you skip y elements in the list to the start of the next row.

Let's say that you do this:
int a[2][4] = { { 1, 2, 3, 4 }, {5, 6, 7, 8 } };

That would be stored like:
12345678

a[1][2] would be 1*4+2 = the 6th element after the start of the list (7).

==============
There's another way, which is to treat a two-dimensional array as an array-of-arrays. Then a[1] would be a pointer to an array of 4 integers, and a[1][2] would be the second element after the start of the array that a[1] points to.

But that requires a lot more work to set up, and can leave the array scattered in many different memory locations.

2007-08-10 02:37:11 · answer #1 · answered by McFate 7 · 0 0

Memory Representation Of Multidimensional Array

2016-12-17 19:17:10 · answer #2 · answered by ? 4 · 0 0

Memory is made up of Rows and Columns. You simply supply and address, which is divided up into two parts, the row part and the column part. We use X amd Y coordinates and that is how you get to a location. Most memories address a byte (8 bits) of information but depending on the type of instruction or data that you address, you could read/write as much as 64 bits, or 8 bytes. Now this is a very simple explanation. If you want more details then you must understand the hardware structure of the machine in which the memory is addressed.

2007-08-10 01:41:15 · answer #3 · answered by Richard F 3 · 0 0

The elements are usually arranged in a linear fashion with a pointer (made up of the coordinates of the array) finding the required value. Array (3,3) 123123123 ... ^Pointer (1,3)

2016-03-12 21:38:08 · answer #4 · answered by Anonymous · 0 0

fedest.com, questions and answers