Group Members
Group Members
3
Example of Arrays:
For Example :
1. List of employees in an organization.
2. Test scores of a class of students.
3. List of customers and their telephone numbers.
4. List of students in the college.
For Example, to represent 100 students in college , can
be written as
student [100]
Here student is a array name and [100] is called index
or subscript.
4
Types of Arrays
Types of Array :
1. One-dimensional arrays
2. Two-dimensional arrays
3. Multidimensional arrays
5
One-dimensional Arrays.
6
One-dimensional Arrays.
and the computer store these numbers as shown below :
number [0]
number [1]
number [2]
number [3]
number [4]
The values can be assigned to the array as follows :
number [0] = 35;
number [1] = 40;
number [2] = 20;
number [3] = 57;
number [4] = 19;
7
DECLARATION OF ONE-DIMENSIONAL ARRAYS :
8
Example
For example :
9
INITIALIZATION OF ONE-DIMENSIONAL ARRAYS :
10
Compile time initialization
Example :
int number[3] = {4,5,9};
Here array number of size 3 and will assign 4 to first
element(number[0]), 5 is assign with second
element(number[1]) and 9 is assign with third
element(number[2]).
11
Compile time initialization
Example :
int number[ ] = {1,2,3,4};
12
Run time initialization :
In run time initialization, the array is explicitly initialize at run
time.
This concept generally used for initializing large arrays.
Example:
for(i=0; i < 100; i++)
{
if( i < 50)
sum[i] = 0.0;
else
sum[i] = 1.0;
}
Here first 50 elements of the array sum are initialized to 0
and the remaining 50 elements are initialized to 1 at run
time. 13
Two-dimensional Arrays
For example:
int table[2][3];
14
DECLARATION OF TWO-DIMENSIONAL ARRAYS :
type array-name[row_size][column_size];
15
INITIALIZATION OF TWO-DIMENSIONAL ARRAYS :
16
INITIALIZATION OF TWO-DIMENSIONAL ARRAYS :
Example :
int table[ ][3] = {{0,0,0}, {1,1,1}};
If the values are missing in an initializer, they are
automatically set to zero.
Example :
int table[2][3] = {1,1,2};
Here first row initialize to 1,1 and 2, and second row
initialize to 0,0 and 0 automatically.
17
Memory Layout of Two-dimensional array :
18
multi-dimensional Arrays
19
multi-dimensional Arrays
float table[5][4][5][3];
20
Applications Of arrays
21
THANK YOU