I cannot create a 2D array from 2 variables (eg int arr[i][j] not allowed) so how would I create a dynamically sized 2D array?
The dimensions of the array are only known at runtime in my program. The array is to represent a grid. How would I code this in C?
You have to allocate a 1-dimensional array:
And access it like this:
The compiler does exactly this when accessing two-dimensional arrays, and will probably output the same code when
ncan be guessed at compile time.