# Introduction to Arrays

If we want to store a group of data together in one place, then an array data structure we should looking for. This data structure enables us to arrange more than one element, that is why it is a termed as a composite data structure. In this data structure, all the elements are stored in contiguous locations of the memory.

**finite**,

**ordered**and collection of

**homogeneous data**elements. An array is finite because it contains only a limited number of elements. It is ordered because all the elements are stored one by one in contiguous locations of the computer memory in a linear ordered fashion. All the elements of an array are of the same data type (say, integer) only and hence it is termed as a collection of homogeneous data elements.

Following are the some examples:

- An array of integers to store the age of all students in a class.
- An array of strings to store the names of all the villagers in a village.

**Terminology used in Array**

**1. Size of Array: **The number of elements in an array is called the size of the array. The size is also called the length or dimension.

**2. Type of Array: **The type of an array represents the kind of data type it is meant for. for example, an array of integers, an array of character etc.

**3. Base: **The base of an array is the address of the memory location where the first element of the array is located.

**4. Index: **All the elements in an array can be referenced by an index. An index is always an integer value. As each array element is identified by an index, an array element is also termed *sub-scripted* or *indexed* variable.

**5. Range of indices: **Indices of array elements may change from a lower bound (\(L\)) to an upper bound (\(U\)), and these bounds are called the boundaries of an array.

In a declaration of an array in **FORTRAN**(**
DIMENSION A[100]**) the range of indices is from \(1…100\), the range of indices is from 1 to 100. For the same array in **C/C++**(**
int A[100]**)the range of indices is from \(0…99\). However, in **PASCAL **the user can define the range of indices from any lower bound to upper bound. For example, for(
A: ARRAY[-5...19] of integer), the range extends from \(-5,\,-4,\,-3\,…\,18,\,19\).

In terms of \(L\), the lower bound, the index of the \(i^{th}\) element is:

$$index(A[i]) = L + i – 1$$

If the range of the indices varies from \(L\) to \(U\) then the size of the array can be calculated as:

$$size(A) = U – L + 1$$

**5. Words: **Words denotes the size of an element. in each memory location, a computer can store an element of word size of \(w\). This word size varies from machine to machine such as **1 byte** to **8 byte. **Thus,

In the future post we will discuss

This article is contributed by Ram Kripal. If you like eLgo Academy and would like to contribute, you can mail your article to admin@elgoacademy.org. See your article appearing on the eLgo Academy page and help other Geeks. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.