Introduction to Array

Array is the sequential collection of memory variables having same data type.Or, Arrays are a data structure which holds multiple variables of the same data type.
Whenever there is need to store a group of data of the same type in the memory, arrays are used.
Normally variables are used to store specific values.,But Consider the case where a programmer needs to keep track of a number of students of a collage. So far, our initial attempt will be to create a specific variable for each student. It may seems like:-- 
int stud1 = 101;






























































































































































































































































































































int stud2 = 232;
int stud3 = 231;
int stud4 = 234;

this much of line , we will have to write to store the roll of only 4 students, then think how much line of codes we will have to write for 1000s of students???
 It will be a typical problem for us. To overcome this situation we use the concept of array.

Using array,

The replacement of the above example using arrays looks like:

int stud[4];
stud[0] = 101;
stud[1] = 232;
stud[2] = 231;
stud[3] = 234;



We created an array called stud, which has space for four integer variables.And we declared its value using its index number.



Array Declaration:-


Arrays are defined in the same manner as ordinary variables, except that each array name must be accompanied by the size specification.

The general form of array declaration is:


"data_type array_name[size];"


data-type specifies the type of array, size is a positive integer number or symbolic constant that indicates the maximum number of elements that can be stored in the array.

Example:
integer class[50];




This declaration declares an array named height containing 50 elements of type float. 

Comments

Popular posts from this blog

Components of C language

Decision making using if statement

How to make payment for final certificate, migration, provisional for the students of last semester of ptu?