Arrays

Published on December 2016 | Categories: Documents | Downloads: 57 | Comments: 0 | Views: 298
of 8
Download PDF   Embed   Report

Comments

Content

ARRAYS
Prepared By
B.M.Brinda

WHY 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 !!!

INTRODUCTION





An 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 DECLARATION


Syntax:
Data type arrayName [ arraySize ];



Examples:




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

ARRAY INITIALIZATION
Example:

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 ARRAYS


Once 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

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close