Published by: Nuru
Published date: 21 Jun 2021
As for the introduction to arrays, we say that they are the collection of elements of the same data type placed in a consecutive memory location. We can access these individually using the index giving a unique name.
The individual data items in an array are called elements of the array and they all are of the same data type. This makes it easier to calculate the position of each element by simply adding an offset to a base value. The individual elements are characterized by array names and all of them are followed by one or more indices. We enclose these indices or subscripts in the square brackets. We can store five types of value integers with a single identifier. There is no need of declaring five different variables with a different identifier.
Arrays are very useful when store related data items. For instance, grades of students, marks of students, matrix addition, subtraction, etc. These can be both single-dimensional or multidimensional.
In this type, there is the indexing of the first element of the array by the use of subscript of 0.
The subscript 1 indexes the second element of the array in this type.
We can freely choose the n- based index. Usually, programming languages that allow n- based indexing also allow negative index values. It also allows other scalar data types like enumerations or characters that are used in the array.
The most important property of an array is that it stores elements in contiguous memory locations.
Let us take an example:
Int num [5]
Here, the integer value is within the square bracket. We call it a subscript.