C Tutorial C References

C - Multi-dimensional Arrays



Multi-dimensional array can be viewed as arrays of arrays. C allows you to define array of any dimension.

Syntax

//2-dimension array
int MyArray [n][m];    

//3-dimension array
int MyArray [p][q][r]; 

//2-dimensional array with size (2,3)
int MyArray [2][3] = {10,20,30}; 

#include <stdio.h>
 
int main (){
  int numbers[2][3] = {10, 20, 30, 40, 50, 60};
  for(int i = 0; i < 2; i++) {
    for(int j = 0; j < 3; j++) {
      printf("%i ",numbers[i][j]);
    }
    printf("\n");
  }
  return 0;
}

The output of the above code will be:

10 20 30 
40 50 60 

❮ C - Arrays

5