Here's a C program one of my friends had written.
From what I know, arrays had to be initialised at compile time before C99 introduced VLA's, or using malloc
during runtime.
But here the program accepts value of a const
from the user and initialises the array accordingly.
It's working fine, even with gcc -std=c89
, but looks very wrong to me.
Is it all compiler dependent?
#include <stdio.h>
int
main()
{
int const n;
scanf("%d", &n);
printf("n is %d\n", n);
int arr[n];
int i;
for(i = 0; i < n; i++)
arr[i] = i;
for(i = 0; i < n; i++)
printf("%d, ", arr[i]);
return 0;
}