Arrays
Arrays
Arrays
● Contain fixed number of elements of same data type.
● Static Entity- same size throughout the program.
● An array must be defined before it is used.
● Array definition specifies array name, variable type & size.
● Size specifies how many data items the array will contain.
Linear Arrays
Two basic Representation in Memory:
Have a Linear Relationship between the data elements
represented by means of sequential memory locations. i.e.
Arrays
Have the Linear Relationship between the elements
represented by means of Pointer or Links i.e. Linked List
Linear Array is a list of a finite number of n
homogeneous data elements such that all the elements of
the array are referenced respectively by an index and are
stored respectively in successive memory locations.
n is called the length or range of the array.
Length = UB – LB + 1
Representation of Linear Array
in Memory
Let LA be a linear array in the memory of the computer &
LOC(LA[K]) = address of the element LA[K].
Now, as array is the Linear Array, computer does not need to
keep track of the address of every element of LA but need to
track only the address of the first element of the array
denoted by Base(LA) called the base address of LA.
LOC(LA[K]) = Base(LA) + w(K – lower bound)
● where w is the no. of words per memory cell.
For any value, time to calculate LOC(LA[K]) is same.
Representation of Linear Array
in Memory
Find the address for LA[6]