An array is a group of variables (or elements) which are of the same type and occupy adjacent locations in the memory. Every element of the array can hold some data and all the elements are collectively referred using an array name.
An Array name refers to the start of the memory location where the array elements are stored. Elements of the array are accessed by the array name followed by an index (also called subscript) in square brackets. An index denotes the position of the element in the array. Indices start from 0 so the nth element of the array is at the n-1th index position.
Consider an array named
myarray that contain three values. This can be represented as below
myarray = [250, 300, 500]
myarray refers to the first element and contains the integer value 250,
myarray is the second element and has a value 300
myarray is the third element and has a value 500 and so on.
Array declarations have the following syntax:
To declare an integer array named myarray which can hold a maximum of 10 elements
When this array is declared memory is allocated to store 10 integer values next to each other.