Search code examples
carraysmemory-managementsizedefinition

can size of array be determined at run time in c?


As I know, an array needs to have a specific size before compiling time in c.

I wonder why this code still works?

int s;
printf("enter the array size: ");
scanf("%d",&s);

int a[s]; // Isn't s value determined at run time?

Solution

  • Array sizes need to be known with ANSI 89 C. The 99 version of the spec removed this limitation and allowed for variable sized arrays.

    Here is the documentation no the GNU version of this feature