Please tell me why the following code runs even on a strict C-99 compiler
:
#include <stdio.h>
int main()
{
int n;
scanf("%d",&n);
int a[n];
a[1]=10;
a[2]=5;
printf("%d %d",a[1],a[2]);
}
The variable declaration must occur before any other statements in C right? If we so want a dynamically allocated array, we have to use memory allocation functions like malloc()
but how come it is taking and input integer and allocating that sized array?