2D Array


Multidimensional array

  • Multidimensional arrays are ned in much the same manner as one dimensional arrays , except that a separated pair of square bracket is required for each subscript.
  • Thus,a two dimensional array will require two pairs of square brackets, a three dimensional array requires three pairs of square brackets, and so on. In general terms , a multidimensional array definition can be written as ,
    storage class datatype array [Expression 1][Expression 2] ....[Expression n]
  • In the above definition, storage class refers to the storage class of the array , data type is the data type, array is array name, ans expressions are positive valued integer expression that indicates the number of array elements associated with each subscript . The storage class is optional. The storage class is automatic for arrays that are defined inside and external for arrays defined outside a function.

Initianalising 2D Array

  • It would better be understood by example ,
    int arr_name={
    {21,76},
    {5,91},
    {1,98}
    }
    or like int arr_name={21 , 76 , 5 , 91 , 1 , 98};
  • It is important to remember that, while initializing in a 2-D array , it is necessary to mention the second bracket,whereas first bracket is optional.
    eg. int array [3][]={2 , 6 , 4 , 7 , 2 , 5}; is not a valid expression.
    whereas int array [][3]={2 , 6 , 4 , 7 , 2 , 5}; is perfectly a valid expression.

  • Print Page