C語(yǔ)言中,二維數(shù)組的初始化可以通過(guò)以下幾種方式進(jìn)行:
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];
}
}