2. Arrays
●It is derived data type
●Arrays are collection of data that belong to
same data type
●Arrays are collection of homogeneous data
●Array elements can be accessed by its position
in the array called as index
●Values in an array are identified using array
name with subscripts
●Also known as subscripted variable
●It is fixed-size collection of elements
3. ● Following are types of array
●One-dimensional Array
●Two-dimensional Array
●Multi-dimensional Array
4. One-dimensional Array
●A collections of variables are given one variable name
using only one subscript and such a variable is called a
single-subscripted variable or one dimensional array
●Syntax
data_type ArrayName[size];
data_type : is a valid data type like int, float or char
Arrayname : is a valid identifier
size : maximum number of elements that can
be stored in array
5. Arrays
Array index starts with zero
The last index in an array is num – 1 where
num is the no of elements in a array
int a[9] is an array that stores 9 integers
index 0 1 2 3 4 5 6 7 8
elements
Memory address 100 102 104 106 108 110 112 114 116
6. Initilization of Array
●After declaring the array, all the elements of
array must be initialized other wise they will
contain garbage value
●At compile time
●At run time
data_type ArrayName[size] = {list of values}
int marks[5] = {55, 63,67,78,59};
7. Each value is treated as an element of the array
and is stored in the memory as follows
marks
55 0
63 1
67 2
78 3
59 4
10. Two Dimensional Array
●To store following data of 4 students
201 202 203 204 205
09BCA07 45 42 41 56 46
09BCA14 46 55 70 49 56
09BCA45 65 61 68 42 56
09BCA115 46 38 39 45 42
11. Two Dimensional Array
● StudentDetailsIJ
● Where,
StudentDetails represents a matrix
I represents no. of rows
J represents no. of columns
It is collection of rows and columns