C語言中,二維數組的初始化可以通過以下幾種方式進行:
int arr[3][3] = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
int arr[3][3];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
arr[i][j] = i * 3 + j + 1;
}
}
int temp[9] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
int arr[3][3];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
arr[i][j] = temp[i * 3 + j];
}
}