Array Definition-: In many application we need to handle a large volume of data in terms of reading,processing and printing. to process such large amount of data we need a powerful data type that would facilitate efficient sorting accessing and manipulation of data items. C support a derived data type known as array.
An array is a fixed size size sequenced collection of elements of the same data. In others words we can say “a collection of same data type in large value called array ” Example —
a list of employ in an organization, a number of school students
Types of Arrays:- Arrays are three types
- one dimensional arrays
- two dimensional arrays
- multidimensional array
One dimensional arrays:- A list of items can be given one variable name using only one subscript and such as variable called a single subscripted variable or a one dimensional arrays. IN other words we can say all the data are store in one variable name called one dimensional arrays as like all the student of a school height are calculate x[1],x[2],x[3]…….x[n]
The subscript start with X[0]
- student[0]=135;
- student[1]=130;
- student[2]=134;
- student[3]=33;
Declaration of One dimensional arrays-: Like any other variable arrays must be declared before we can used so that the compiler can allocated space for term in memory.
example — float height[50]; int gruops[20]; char name[30];
Rules of declaration of arrays .
- The size should be a numeric constant or symbolic constant
- any reference to the arrays outside to the array the declared limits would not necessary cause an error. Rather it might result in unpredictable programe result.
Initialization of one dimensional arrays -: After declaration of arrays its elements must be initialized otherwise they will contain “garbage” there are two type
- compile time
- At run time
Compile time initialization :-We can initialization the elements of arrays in the same way the ordinary variable when they are declared as like ……. array name[size ]= {list of values};
int height[3]={0,0,0};
will declare the variable number as array of size 3and will assign zero to every elements . If the number of values in the list is less than a number of elements then onley that many elements will be initialized .The remaining elements will be set to zero automatically for like
float total[5]={o.0,2.12,-10}
it will initialize the first three value o.0,2.12,-10 and leave it to other values.
Run time initialization-: see the example
——————
------- for (i=0 ; i <100 ;i+1 ) { if i <50 sum [i] =0.0; else sum[i]=1.0; }
The first 50 elements of the array sum are initialized to zero while the remaning elements are initialized to 1.0 at run time.
An array can be explicitly initialized at run time.
Two dimensional arrays-: In two dimensional array variable store two variable data value different types. Two dimensional array are stored in memory as like
type array name[row_size][column _size];
Initializing two dimensional arrays -: like one dimensional array, two dimensional array may be initialized by following declaration as like
int table [2][3]= {0,0,0,1,1,1}
Multi dimensional array :- C allow arrays three or more dimensional. as like
type array name [a1][a2][a3].......[a n];
where is the size of array
int survey [3][5][6]
float table [5] [6] [7];