Arrays 197
In the same way array of different data types are declared as follows
char ch[10];
flo a t re al [10];
long num [5] ;
7.2 ARRAY INITIALIZATION
The Array initialization is done as given below
in t a [5]={1,2,3,4,5};
Here, 5 elements are stored in an array 'a'. The array elements are stored sequentially in separate
locations. Then question arises how to call individually to each element from this bunch of integer
elements. Reading of array elements begins from 10'.
Array elements are called by array names followed by the element numbers. The given Table 7.1
explains the same.
Table 7.1 Calling Array Elements
a [0] refers to 1st element i.e. 1
a [ 1 ] refers to 2nd element i.e. 2
a [ 2 ] refers to 3rd element i.e. 3
a [ 3 ] refers to 4th element i.e. 4
a [4 ] refers to 5th element i.e. 5
7.3 DEFINITION OF ARRAY
Array is a collection of elements having similar data types in which each element is unique one and
located in separate memory locations.
7.4 CHARACTERISTIC OF ARRAY
1) The declaration int a [5] is nothing but creation of 5 variables of integer types in the memory.
Instead of declaring five variables for five values, the programmer can define them in an array.
2) All the elements of an array share the same name, and they are distinguished from one another
with the help of an element number.
3) The element number in an array plays major role for calling each element.
4) Any particular element of an array can be modified separately without disturbing other
elements.
int a [5]={1,2,3,4,8};
If a programmer needs to replace 8 with 10, he/she need not require to change all other numbers
expect 8. To carry out this task the statement a [ 4 ] = 10 can be used. Here other three elements
are not disturbed.
5) Any element of an array a [ ] can be assigned/equated to another ordinary variable or array
variable of its type.
For example
b= a [2] ;
a [2] =a [3];
a) In the statement b= a [2] or vice versa, value of a [2] is assigned to xb', where xb' is an
integer.

Get Programming and Data Structures now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.