Multidimensional Arrays
2001-12-06 02:49:10
Category: c:strings
Description: Example of multidimensional arrays in c
Author: detour
Viewed: 7296
Rating: (40 votes)


/* multiarry.c written by detour@metalshell.com
 *
 * simple example of multidimensional arrays
 *
 * http://www.metalshell.com/
 *
 */
 
#include <stdio.h>
 
int main() {
  int x, y;
 
  /* A multidimensional array can be thought of as an array
   * inside an array.  The declaration of grid is making 3 arrays
   * of size 2.
   */
  int grid[3][2] = { {10,20},{30,40},{50,60} };
 
  /* The table of grid looks like
   *    ---------
   *  0| 10 | 20 |
   *  1| 30 | 40 |
   *  2| 50 | 60 |
   *    ---------
   *      0    1
   *
   */
 
  
  for (x=0;x<3;x++) 
    for (y=0;y<2;y++) {
      printf("row = %i\ncol = %i\nvalue = %i\n", x, y, grid[x][y]);
    }
 
}