# 二維（多維）陣列

``````int maze[5][10];
``````

``````#include <stdio.h>
#define ROW 5
#define COLUMN 10

int main(void) {
int maze[ROW][COLUMN];

for(int i = 0; i < ROW; i++) {
for(int j = 0; j < COLUMN; j++) {
maze[i][j] = (i + 1) * (j + 1);
}
}

for(int i = 0; i < ROW; i++) {
for(int j = 0; j < COLUMN; j++) {
printf("%d\t", maze[i][j]);
}
putchar('\n');
}

return 0;
}
``````

``````1       2       3       4       5       6       7       8       9       10
2       4       6       8       10      12      14      16      18      20
3       6       9       12      15      18      21      24      27      30
4       8       12      16      20      24      28      32      36      40
5       10      15      20      25      30      35      40      45      50
``````

``````int maze[2][3] = {
{1, 2, 3},
{4, 5, 6}
};
``````

``````int maze[2][3] = {
1, 2, 3,
4, 5, 6
};
``````

`int` 整數陣列來說，每一位移量是 4 個位元組，而指定存取 `maze[4]`，相當於指定存取相對於 `maze[0]` 四個位移量的記憶體空間。

``````#include <stdio.h>
#define ROWS 2
#define LEN 3

int main(void) {
int maze[ROWS][LEN] = {
{1, 2, 3},
{4, 5, 6}
};

for(int i = 0; i < ROWS; i++) {
int *row = maze[i];
for(int j = 0; j < LEN; j++) {
printf("%d\t", row[j]);
}
printf("\n");
}
}
``````

``````int arr[2][4][6];
``````