Syntax of VLAs in C

void fun(int size)
{
int arr[size];
// code
}

Note: In C99 or C11 standards, there is a feature called flexible array members, which works the same as the above. 

Variable Length Arrays (VLAs) in C

In C, variable length arrays (VLAs) are also known as runtime-sized or variable-sized arrays. The size of such arrays is defined at run-time.

Variably modified types include variable-length arrays and pointers to variable-length arrays. Variably changed types must be declared at either block scope or function prototype scope.

Variable length arrays are a feature where we can allocate an auto array (on stack) of variable size. It can be used in a typedef statement. C supports variable-sized arrays from the C99 standard. For example, the below program compiles and runs fine in C.

Similar Reads

Syntax of VLAs in C

void fun(int size){ int arr[size]; // code}...

Example of Variable Length Arrays

The below example shows the implementation of variable length arrays in C program...