Loading, please wait...

Single Dimensional Array

A single dimension array is the simplest form of an array. The array is given a name and its elements are referred to by their subscripts or indices. A one-dimensional array is used to store a large number of items in memory. It references all the items in a uniform manner.

 

 

Representation of Linear Arrays in Memory

The memory of computer is simply a sequence of addressed locations as shown in the figure showing Computer Memory.



500

501

502

.

.



Assume myarray be a linear array stored in the memory of computer.

Add(myarray[k])

 address of the array[k] element of the myarray

 

As the elements of the myarray are in consecutive memory cells, the computer doesn’t need to keep track of the address of the every element of the array. It only needs to keep track of the address of the first element of the array which is denoted by:

Base(myarray)

It is called the base address of the myarray.

 

Using this base address Base(myarray), the computer computes the address of any element of the array by using the following formula:

Add(myarray[k]) = Base(myarray) + w(k-lower bound)

Where w is the size of the data type of the array myarray.

Observe that the time to compute Add(myarray[k]) is essentially the same for any value of k. Further, given any subscript k, one can locate and access the elements of myarray[k] by other element of the array.