Variable Length Arrays (VLAs) in C Last Updated : 07 Oct, 2025 Comments Improve Suggest changes 66 Likes Like Report 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. C++ #include <stdio.h> // function to initialize array void initialize(int *arr, int size) { for (int i = 0; i < size; i++) { arr[i] = i + 1; } } // function to print an array void printArray(int size) { // variable length array int arr[size]; initialize(arr, size); for (int i = 0; i < size; i++) { printf("%d ", arr[i]); } } int main() { int n; printf("Enter the Size: "); scanf("%d", &n); printArray(n); return 0; } OutputEnter the Size: 51 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}; C++ #include <stdio.h> int main() { int n = 5; int arr[n] = {0}; for (int i = 0; i < n; i++) printf("%d ", arr[i]); printf("\n"); return 0; } Note : However, many modern compilers like GCC and Clang allow this as an extension, so they let it compile without error.Advantages of VLAsMakes code more flexible than fixed-size arrays.No need to use dynamic memory functions (malloc/free) for temporary arrays.Syntax is simple and similar to normal arrays.Disadvantages of VLAsVLAs are stored on the stack, which has limited memory, very large VLAs may cause stack overflow.Cannot be used as global or static arrays.Not guaranteed to be supported on all compilers (especially in modern standards like C11). Create Quiz Comment K kartik 66 Improve K kartik 66 Improve Article Tags : C++ cpp-array C Array and String Explore C++ BasicsIntroduction to C++3 min readData Types in C++6 min readVariables in C++4 min readOperators in C++9 min readBasic Input / Output in C++3 min readControl flow statements in Programming15+ min readLoops in C++7 min readFunctions in C++8 min readArrays in C++8 min readCore ConceptsPointers and References in C++5 min readnew and delete Operators in C++ For Dynamic Memory5 min readTemplates in C++8 min readStructures, Unions and Enumerations in C++3 min readException Handling in C++12 min readFile Handling in C++8 min readMultithreading in C++8 min readNamespace in C++5 min readOOP in C++Object Oriented Programming in C++8 min readInheritance in C++6 min readPolymorphism in C++5 min readEncapsulation in C++3 min readAbstraction in C++4 min readStandard Template Library(STL)Standard Template Library (STL) in C++3 min readContainers in C++ STL2 min readIterators in C++ STL10 min readC++ STL Algorithm Library3 min readPractice & ProblemsC++ Interview Questions and Answers1 min readC++ Programming Examples4 min read Like