1
Array
2
Objective:
1. Introduction to array
2. Able to define array data type (one and two dimensions of array)
3. Able to modify program according to user requirements
Introduction:
Array is a collection or a data structure of a fixed number of components where in all of the
components are of the same type.
To declare an array type of data structure the command we use as below format.
One dimension array
<data type> <variable_name>[subscript/index]
Subscript or index shall start with 0.
Example of an array data structure name Array1, which has 10 components, of type integer.
The illustration of the above array.
Index / Subscript
Two dimension array
<data type> <variable_name>[subscript/index] [subscript/index]
Subscript or index shall start with 0.
Example of an array data structure name Array1, which has 10 components, of type integer.
The illustration of the above array.
int Array1[10];
0
1
2
3
4
5
6
7
8
9
int matrix1[3][2];
[0][0]
[1][0]
[2][0]
[0][1
[1][1]
[2][1]
3
Part A:
Q1: Definition of array data structure
Array is a collection of a fixed number of components/elements where all of the
components/elements are of the same type.
Q2: Declare the below array type variable.
i. Variable name is markah, consist of 20 components with data type of float.
__int markah[20];________________________________
ii. Variable name is terracehouse consist of 15 component with data type of integer.
__int terracehouse[15];__________________________
iii. Variable name is Matrix1 consist 5 rows and 5 column with data type of double.
__double Matrix1[5][5];___________________________
iv. Variable name is flathouse consist of 15 and 10 column with data type of integer.
__int flathouse[15][10];_________________________