行数ではなく列数の値がわかっている場合、mallocを使用してCで配列を割り当てることができるかどうかを尋ねたかった.
int Array[runtime value][N];
行数ではなく列数の値がわかっている場合、mallocを使用してCで配列を割り当てることができるかどうかを尋ねたかった.
int Array[runtime value][N];
はい。動的に割り当てることができます。
// Allocate the columns
int** two_dimensional_array = malloc(COLUMNS * sizeof(int*));
// Find the number of rows on runtime
// however you please.
// Allocate the rest of the 2D array
int i;
for (i = 0; i < COLUMNS; ++i) {
two_dimensional_array[i] = malloc(sizeof(int) * ROWS);
}
または、可変サイズ (C99) でスタック上に 1 つ持つことができます。
int n;
scanf("%d", &n);
int arr[n][COLUMNS];