Array Programming In C

void main()
{
 	int a ; 
	a = 10 ;
	a = 20 ; 
	printf ( "\nx = %d", a );		 
}
		  

The final output of this program is 20.Initially the value 10 is assigned to the variable a.But then a new value 20 is assigned to variable a.The variable a is ordinary variable and is not capable of holding multiple values. However,there are many circumstances where we want a single variable to store multiple values.

Let us assume that we want to save the salary of 100 employees.This can be done in two ways -

1. Create 100 variables to store the salary of 100 employyes.

2. Create one variable i.e.array capable of storing or holding all the hundred values.

The second option is the preferred option since it is much easier to handle one variable than 100 variables.

Thus,array is collection of data items of same data type.

Declaration of array

int Emp[100];

Here int specifies the data type of the array.100 gives the dimension of the array and 100 elements can be saved in the array Emp.