One-Dimensional Array



A list of items having one variable name, one subscript known as an One-dimensional array. The elements of an array are stored in continuous memory locations. The declaration form of one-dimensional array is

Syntax :- Data_type array_name [size];

E.g.: int numbers [5];

The following declares an array called ‘numbers’ to hold 5 integers and sets the first and last elements. C arrays are always indexed from 0. So the first integer in ‘numbers’ array is numbers[0] and the last is numbers[4].

numbers [0] = 1; // set first element
numbers [4] = 5; // set last element

This array contains 5 elements. Any one of these elements may be referred to by giving the name of the array followed by the position number of the particular element in square brackets ([]). The first element in every array is the zeroth element. Thus, the first element of array ‘numbers’ is referred to as numbers[ 0 ], the second element of array ‘numbers’ is referred to as numbers[ 1 ], the fifth element of array ‘numbers’ is referred to as numbers[ 4 ], and, in general, the n-th element of array ‘numbers’ is referred to as numbers[ n - 1 ].

Initialization of one-dimensional array:
One dimensional array can be initialized as follows:
E.g.: int arr[5]={1, 2, 3, 4, 5};