CS561-SPRING 2002

TOPIC:CS105-ARRAYS

 

                            Multi dimensional arrays are used to manipulate data, numeric or otherwise in the form of matrices, but stored in array locations. Conceptually, they are matrices, but the method they are stored are typical of array elements and are viewed as such too. The following declaration example illustrates a typical two dimensional array for a simple C++ program,

Example ::  int TWO_DIM [5][7];

             The above declaration now creates a two dimensional array named as TWO_DIM having 5 rows and 7 columns and that holds integer elements only and would be perceived as being laid out in the manner illustrated in the diagram below,

    (0,0)      (0,1)      (0,2)     (0,3)     (0,4)     (0,5)    (0,6)
       *              (1,6)
       *              (2,6)
       *              (3,6)
       *        *        *        *        *        *    (4,6)

                  Data elements are simply accessed by specifying their location in the array, for example

 TWO_DIM[2][4] = 10;       would assign the element in the third row and fifth column an integer value of 10.

 

<=PREV                                       HOME                                               NEXT=>