You are on page 1of 8

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

You might also like