Related but not quite duplicate as it discusses C++:
can we give size of static array a variable
I am definin
You cannot declare a static
array of variable size because its space is allocated in the Data Segment (or bss segment in case of an uninitialized variable). Hence the compiler needs to know the size at the compile time and will complain if the size is not a constant.
The underlying reason for this is the Data Segment size contributes to the size of the executable being generated, which obviously is created at compile time, and hence has to be fixed.