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 –

Syntax: –

Data_Type Array_Variable_Name[Size];

Ex: –

int a[5];
float f[3];
char ch[10];

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.

Simple Variable

Array Variable

int a,b,c,d,e; int a[5];

 

(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: –

  1. Once the size of array is fixed, we cannot change the size of array. Otherwise our data will be lost.
  2. 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.
  3. Array hold n number of elements or values of similar type.

Type of array –

  1. One dimensional array
  2. Two dimensional array
  3. Multiple dimensional array
Advertisements