8.
0 Arrays
Many applications require the processing of multiple data items that have common
characteristics.
An array is a collection of homogeneous data items.
The individual data items can be characters, integers, floating point numbers etc. However, they
must be of the same type.
Secondary data type which is indexed
Each array element is referred to by specifying the array name followed by one or more
subscripts (thus arrays are sometimes referred to as subscripted data type), with each subscript
enclosed in square brackets.
X
10 20 30 40 50 …
X[0] X[1] X[2] X[3] X[4] …
X is a one dimensional array, X is the name of the array
In most programming languages, Array indexing starts from zero(0)
X[i] refers to the ith element of array X
In a two dimensional array, X[i][j] is the element at row i, column j.
8.1 Defining an array
Arrays are defined in much the same manner as ordinary variable, except that each array
name must be accompanied by a size specification(maximum number of elements)
Example
data type array_name[expression]
eg int X[100] - X is an array of integer numbers with a maximum size of 100 integer
numbers.
Operations that can be performed on arrays( i.e created array) :
Traversing
Insertion
Deletion
Search
Update
Sort
merge
8.2 Multidimensional Array
A two dimensional array requires two pairs of square brackets, a three dimensional array will
require three pairs of square brackets and so on.
Multi dimensional arrays are defined in much the same manner as one dimensional array.
Example
int matA[20][15], matB[20][15]
double records[100][66][255]
9.0 Structures
Consists of heterogeneous data items.
A single structure might contain integer elements, floating – point elements and character
elements
Individual structure elements are referred to as members.