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[0]
refers to the first element and contains the integer value 250, myarray[1]
is the second element and has a value 300 myarray[2]
is the third element and has a value 500 and so on.
Array declarations have the following syntax:
variabletype arrayname[limit];
To declare an integer array named myarray which can hold a maximum of 10 elements
int myarray[10];
When this array is declared memory is allocated to store 10 integer values next to each other.
Nothing yet..be the first to share wisdom.