A Variable Length Array is an array whose size is not fixed at compile-time, but instead is decided at runtime.
- Stored on the stack (automatic storage). Their size is determined when execution reaches the declaration.
- They must be declared inside a function (block scope) or in a function prototype scope, not globally.
- VLAs were introduced in the C99 standard, some later standards (like C11) made them optional, so not all compilers may support them.
Output
Enter the Size: 5
1 2 3 4 5
- Unlike fixed-size arrays, VLAs cannot be initialized using {0} in standard C.
- This works only for arrays with compile-time constants size, e.g, int arr[5] ={0};