Arrays

Embed Size (px)

DESCRIPTION

ARRAYS

Citation preview

ARRAYS

ARRAYSPrepared By B.M.BrindaWHY ARRAYS?Why do we need arrays?To handle similar types of data.

Imagine a world without arrays.Example, If the user want to store marks of 100 students, User may create 100 variables to store data !!!

INTRODUCTIONAn array is a sequence of data item of homogeneous value(same type).Each block of array is stored consecutively in memory.Huge amount of data can be stored under single variable name.Searching of data item is faster.

ARRAY DECLARATIONSyntax: Data type arrayName [ arraySize ];

Examples: int list[10];char num[15];float hat[20];

ARRAY INITIALIZATIONExample: int num[10];

num[0]references the first element in the array.num[9]references the last element in the array.

int num[6]={2,4,6,7,8,12};

Individual elements can also be initialize as:num[0]=2;num[1]=4;num[2]=6;num[3]=7;num[4]=8;num[5]=12;

LENGTH OF ARRAYSOnce an array is created, its size is fixed. It cannot be changed. For Example, int arr[10];

You can not insert any number to arr[11] location because it is not initialized.

ONE DIMENSIONAL ARRAY

MULTI DIMENSIONAL ARRAY