ARRAY :
ARRAY An ARRAY is a group of related data items,that share a common name.in an array all data items are of same data type.array are made up of primary data types.a particular value is indicated by writing a number called as index or subscript. individual values in an array are called elements.
Example of array :
Example of array We can define an array name salary to represent a set of salaries of a group of employees.
salary[10]
Represents the salary of 10 employees.
Types of array :
Types of array One-Dimensional Array
Two-Dimensional Array
Multi-Dimensional Array
One-Dimensional Array :
One-Dimensional Array A list of items can be given one variable name using only one subscript is called as one dimensional array.
Declaration of array :
type variable_name[size];
Example
int salary[10];
float salary[10];
Continued.. :
Continued.. In C, arrays starts at position 0. The elements of the array occupy adjacent locations in memory. C treats the name of the array as if it were a pointer to the first element.
E.g. Int x[5];compiler reserves five storage locations as follows:
x[0],x[1],x[2],x[3],x[4]
Initialization of array :
Initialization of array We can initialize an array same as that of initialization of variable name.
The syntax is:
static type variable_name[size]={list of values};
Example
int x[3]={1,2,3};
Will be equivalent to:
X[0]=1, x[1]=2, x[2]=3;
Continued.. :
Continued.. Size may be omitted.
static int counter[]={1,1,1,1};
DRAWBACKS:
There is no convenient way to initialize only selected elements.
There is no shortcut method for initializing a large number of array elements.