Array: – It is a derived data type. It is a collection of elements of similar type. An array may have collection of element based upon specifying the size of array. In order to maintain every individual element in array, subscript or index number is assigned inside () pair of square bracket. The size of array always start from 0 to size -1.
Declear of array variable –
int a; float f; char ch;
Advantage of an Array: –
(1) It reduces the program length (By avoiding many simple variables which are created to hold values).
Ex: – Suppose we have to store five values.
|int a,b,c,d,e;||int a;|
(2) The memory address of all subscript of an array will be allocated in contiguous (Continuous) way.
(3) The operation an array in order read modify or display is very easy because of contiguous memory location.
Disadvantage of an array: –
- Once the size of array is fixed, we cannot change the size of array. Otherwise our data will be lost.
- If we do not store the value as per the given size of array then empty subscript will be useless and the memory will be wasted.
- Array hold n number of elements or values of similar type.
Type of array –
- One dimensional array
- Two dimensional array
- Multiple dimensional array