Name: Karthick Seshadri RC Code: 1173 (Thiagarajar College of Engineering, Madurai)
Name: Karthick Seshadri RC Code: 1173 (Thiagarajar College of Engineering, Madurai)
RC Code: 1173
(Thiagarajar College Of
Engineering,Madurai)
Arrays
Slides for the
alternate_assignment_part3_I
ndian_language
What is an Array?
A data structure to hold a collection of
homogeneous items.
An array has a name and is
characterized by a size or capacity.
Arrays are basically structures that can
hold multiple values under the same
name for ease of access and processing.
An array can be constructed out of any
data type like int, char, float, double and
so on.
3
Memory Layout
The elements of an array are
contiguously stored in memory.
The address of the first element in an
array is called the Base Address.
Typically Arrays are indexed from 0.
10
20
30
40
50
4
4
Array creation
<data type> <Name of the array>
[size]
For e.g: int arr[20];
Creates an array large enough to hold 20
integers.
Array Indexing
arr[2]
Refers to the third element at the index
2.
[] -> subscript operator.
2D - Arrays
Can be used to store a table of items
Row/Colum
n Index
10
20
30
40
50
60
70
80
90
20
30
40
50
60
70
80
90
50
80
30
60
90
Column major
10
40
70
20
10
Arrays - Applications
Implementing other data structures
Stacks, queues, heaps, trees and so on.
String Manipulation
Manipulating a set of records
Binary Search
11