Is there some overhead of using variable-length arrays? Could the size of array be passed via command line argument at run time? Why is it introduced, compared to automatic
I just wonder if there is some overhead of using variable-length arrays?
Nope
Can the size of array could be passed via command line argument at run time?
Yes.
Why is it introduced, compared to automatic and dynamically allocating an array?
Automatic allocated only allows a fixed size known at compile time.
Dynamically allocating (malloc) will store the array on the heap, which has a large memory space, but is slower to access.
VLA works by placing the array in the stack. This makes allocation and access extremely fast, but the stack is usually small (of a few KB), and when the VLA overflowed the stack, it's indistinguishable from an infinite recursion.