For a 1d array yo have to specify the size don't you? You can't just have
int arr[];
Otherwise, the compiler couldn't generate the code necessary to move the stack pointer down the required distance to create space for your array.
You can do:
int arr[] = {2, 4, 5};
for example, because the compiler can figure out from this, that you need 3 * sizeof(int).
In the same way you can do:
int arr[][2] = {{2, 3}, {4,4}}; |
because once again the compiler can figure out the size of memory needed from that.
In general, for multi-dimensional arrays, if you're going to be initialising it directly as shown above, you can leave out the first dimension.
The same logic applies on the heap, you can't just do:
int *arr = new int[];
, because how does the system know how much space to allocate? In this case though, you can't do the same sort of direct initialisation, so you have to supply all the dimensions to get the right amount of space allocated.
EDIT:
It's occurred to me that your question may be how to create a multi-dimensional array on the heap.
In the case of a 2d array of int, which is simply an array of arrays, your basic type would be pointer to array of int, so:
int (* numbers)[4] = new int[4][4];
You still need both dimensions, and the second dimension must be a constexpr