Mis Presentation

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

INTRO TO

LEARNING
ARRAYS
WHAT IS AN ARRAY?

01

A variable is a memory location that can store a value. It can be


thought of as a box in which values are stored. The value held in
the box can change, or vary. But each variable can only hold one
item of data.

02

An array is a series of memory locations – or ‘boxes’ – each of


which holds a single item of data, but with each box sharing the
same name. All data in an array must be of the same data type
.
UNDERSTANDING
ARRAYS
THINK OF AN ARRAY AS A ROW OF CELLS, EACH

CELL REPRESENTS AN ELEMENT:

NAMING ARRAYS, ARRAYS ARE NAMED LIKE

VARIABLES. THE NUMBER IN BRACKETS

DETERMINES HOW MANY DATA ITEMS THE

ARRAY CAN HOLD.

THE ARRAY SCORE(9) WOULD ALLOW TEN DATA

ITEMS TO BE STORED.

ANY FACILITY THAT HOLDS MORE THAN ONE

ITEM OF DATA IS KNOWN AS A DATA

STRUCTURE. THEREFORE, AN ARRAY IS A DATA

STRUCTURE.

Advantage of Array

1) Code Optimization: Less code to the


access the data.
2) Ease of traversing: By using the for loop,
we can retrieve the elements of an array
easily.
3) Ease of sorting: To sort the elements of
the array, we need a few lines of code only.
4) Random Access: We can access any
element randomly using the
Disadvantage of Array

Fixed Size: Whatever size, we define at the time of


declaration of the array, we can't exceed the limit.
So, it doesn't grow the size dynamically like Linked
List which we will learn later.

Properties of Array
The array contains the following properties.
1. Each element of an array is of same data
type and carries the same size, i.e., int = 4
bytes.
2. Elements of the array are stored at contiguous
memory locations where the first element is
stored at the smallest memory location.
3. Elements of the array can be randomly
accessed since we can calculate the address of
each element of the array with the given base
address and the size of the data element.
Declaration of Array
Types of Array

one -Dimensional Array

A one-dimensional array is a
kind of linear array. It involves
single sub-scripting. The []
(brackets) is used for the
subscript of the array and to
declare and access the
elements from the array.
Syntax: DataType ArrayName
[size];
For example: int a[10];

Multi-Dimensional Arrays

An array involving two subscripts [] [] is known as


a two-dimensional array. They are also known as
the array of the array. Two-dimensional arrays
are divided into rows and columns and are able
to handle the data of the table.
Syntax: DataType ArrayName[row_size]
[column_size];
For Example: int arr[5][5];

You might also like