If I have an array which its size is based on the user input, from some material, I need to use malloc function to allocate memory for that array what is known dynamic array. Don't forget to free it.
That's fine, however, I like to try things out even I know the program will crash.
I have written some test program on my Mac using C language like this:
int width = 0;
//get user input, and assign the input value to width, for example, 3
char * array_var[width];
and width is an int, its value will be assigned by the user input. The point is, this program work as expected, for example, in command line, I input 3, then array_var length is 3, its size is 3 * sizeof(char *).
Can anyone explain why it works? I thought array definition like this, its size must be explicitly determined at compile time. I am lost.