1
Multidimensional Arrays Arrays can have more than one dimension. The declaration for a two-dimensiona l array is: type variable[size1][size2]; /* Comment */ For example: int matrix[2][4]; /* a typical matrix */ Notice that C does not follow the notation used in other languages of matrix[10,12]. To access an element of the matrix, we use the notation: matrix[1][2] = 10; C allows the programmer to use as many dimensions as needed (limited only by the amount of memory available). Additional dimensions can be tacked on: four_dimensions[10][12][9][5];

multidimensional arrays.docx

Embed Size (px)

Citation preview

Page 1: multidimensional arrays.docx

Multidimensional ArraysArrays can have more than one dimension. The declaration for a two-dimensiona larray is:type variable[size1][size2]; /* Comment */For example:int matrix[2][4]; /* a typical matrix */Notice that C does not follow the notation used in other languages ofmatrix[10,12].To access an element of the matrix, we use the notation:matrix[1][2] = 10;C allows the programmer to use as many dimensions as needed (limited only by theamount of memory available). Additional dimensions can be tacked on:four_dimensions[10][12][9][5];