Why can't variable length arrays in C be declared as static? For example, this declaration is not allowed:
static char str1[lengthOfaString];
When applied to a local identifier, the static keyword specifies that the object designated by that identifier has static storage duration. That means the object exists for the entire life of the program, from before the evaluation of any non-constant expression.
By definition, variable-length arrays have length designated by an expression that is evaluated at runtime, when control reaches the array declaration. The system cannot provide for such an object to have static storage duration because it does not know the object's size until some time after the object must already exist.
Note also that all file-scope variables have static storage duration, and therefore VLAs cannot be declared at file scope at all. Indeed, at file scope, the static keyword has nothing to do with storage duration; instead, in that context it specifies internal linkage.
lengthOfaStringdeclaration pleaselengthOfaStringis anintvariable that holds a length of another string