Why can't the size of an array be initialized with variables in C language?

C99 does not specify that the size of the array can be defined with variables, but initialization will report an error after it is defined.
const int number=100;
int prime [number] = {2};
error message: [Error] variable-sized object may not be initialized;

C
Dec.30,2021

The

standard only says that you can use variables to define an array, but it doesn't say you can initialize the array / laugh

this is because your initializer ({0}) is determined at compile time, and your number is a quantity that can only be determined at run time, so the array is not sure at this time. How do you initialize a definite quantity to an uncertain quantity

Menu