Friday, August 19, 2011

Types of Array

Arrays are mainly of two types:
1)  Linear Array
2)  Non-Linear Array 

Linear Array:
                   This type of array is also called One Dimensional Array. This is also called list array. In the linear array only one subscript is used. It is written either in row or in column form. 

The syntax to define or declare linear array is:
                              data-type array-name [size];
Where data types are integer (int), real (float), double and character (char).

Non-Linear Array or Multi – dimensional array:
                                       Array of having different dimensions or n subscript is in the form of Non-Linear array. Non-linear array are further of n different types as:
  1. a)  Two Dimensional Array
  1. b)  Three Dimensional Array
  1. c)  N-Dimensional Array

Two Dimensional Array:
                                   These arrays are also called double dimensional array. These arrays are in row and column form, so these are also called Row-Column array or square Array.
These arrays have two subscripts and also called double subscripted array.
   
The general syntax to define or declare is :
                                     data-type array-name [row size][column size];

Initialization of 2D array:
                                      2D array can also be initialized with list of values in such a way that elements of first row are initialized first followed by elements of second row and so on.
E.g.
Int marks [3][3] ={  {30, 40, 25}, {21, 33, 38}, {31, 27, 35}};

The above statement initializes a 2D array marks consisting of three rows and three columns. The values 30, 40, 25 are assigned to elements in the row1 and the values 21, 33, 38 are assigned to elements in the row2. Similarly the values 31, 27, 35 are assigned to elements in the row3.

The above example can also be written as:
Int marks [3][3] ={ 30, 40, 25, 21, 33, 38, 31, 27, 35};
                              Row1          Row2         Row3



Previous Next Home
0 Comments
Comments

Leave a Comment

:)) ;)) ;;) :D ;) :p :(( :) :( :X =(( :-o :-/ :-* :| 8-} :)] ~x( :-t b-( :-L x( =))

Twitter Delicious Facebook Favorites More