void f(int n) { double a[n]; } Here, a is a variable-length array (VLA) when n is not an integer constant expression. Its length is determined at run time, unlike a fixed-length array (FLA), whose length comes from an integer constant expression or an initializer. section 6.1.3
The declaration rules impose several practical boundaries:
- A VLA cannot have an initializer. section 6.1.3 section 5.5
- A VLA cannot be declared outside a function. section 6.1.3
- An array-length specification must be strictly positive. section 6.1.3
- The length of an array A can be computed as (sizeof A) / (sizeof A[0]). section 6.1.3
Lifetime begins at the definition
For an ordinary non-VLA automatic object, lifetime starts when its scope is entered. For a VLA, lifetime starts only when execution encounters its definition and ends when its visibility scope is left. Consequently, code earlier in the same block cannot use a pointer to that VLA: its storage cannot exist before the run-time size is known. section 13.3
double E[] = { [3] = 42.0, [2] = 37.0, };
double F[] = { 22.0, 17.0, 1, 0.5, };
!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":3},{\"line\":0,\"ch\":9}],[{\"line\":1,\"ch\":3},{\"line\":1,\"ch\":9}],[{\"line\":0,\"ch\":3},{\"line\":0,\"ch\":9}],[{\"line\":1,\"ch\":3},{\"line\":1,\"ch\":9}]]"}
!@%STYLE%@!
Compare omitted-length arrays whose initializers determine their lengths: E and F are fixed-length double[4] arrays, not VLAs. section 6.1.3

