Array is a variable that can hold more than one value of same type. You specify which of the several values you're referring to at any given time by using a numeric subscript. (Arrays in programming are similar to vectors or matrices in mathematics.)
Arrays are of two types:
- One-dimensional arrays
- Multidimensional arrays
One Dimensional Array : Size of array defines the number of elements in an array. Each element of array can be accessed and used by user according to the need of program.
Syntax :
<array_type> <array_name> [<number of elements in array>];
Example: If the user want to store salary of 100 employee. This can be done by creating 100 variable individually but, by array it's now become simple.
int salary[100];
The following program initializes an integer array with five values and prints the array.
#include <stdio.h>
#include <conio.h>
int main()
{
int a[]={9,8,7,6,5};
int i;
clrscr();
printf("Array elements are\n");
for(i=0;i<=4;i++)
printf("%d\n",a[i]);
getch();
return 0;
}