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];
}
}