I was trying to create a 2d array without mentioning the dimensions like as follows:
int m1[][] = {{1,2}, {3,4}};
I got the following error when compiled:
error: array type has incomplete element type
Is it not possible to create a 2d array on the stack (as opposed to dynamic memory allocation on heap) without mentioning the row and column?
If compiler can’t determine the dimension for an integer 2d array, how does it determines the space requirement for string 2d array. For example,
char *keywords[] = {"auto", "static", "extern", "volatile"};
You can ommit the outer dimension, but not the inner. So this is okay
To your second question:
char *keywords[]is NOT a 2d array! It is an array of pointers. Pointers are not arrays; Arrays are not pointers! (It’s only that arrays decay into pointers to the first element of an array, if used as an rvalue).Update: To actually answer your question: The strings will typically be statically “allocated” in readonly storage (for example directly written in object files/your program). So it’s also wrong to declare your array as
char *[]– it should be aconst char *[].