int num = atoi(argv[1]);
unsigned long times[num];
I have this code and I assumed it won’t compile because I am trying to allocate the array using a value from a command line argument, which compiler doesn’t know at the compile time.
But I compiled this code and it worked.
Can someone explain what is going on here??
Am I misunderstanding the basic concept of static allocation??
C99 allows to allocate an array with a var. This is called variable length arrays aka VLA
I don’t have the C99 in my hand, the section is 6.7.5.2 in C99, and the following links are from the internet.
vla – wikipedia
c99 – wikipedia
be aware that vla is not supported in c++, more information here