title: Difficulty in understanding variable-length arrays in C
body: <p>I was reading a book when I found that array size must be given at time of declaration or allocated from heap using malloc at runtime.I wrote this program in C :</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  
  int main() {
    int n, i;
    scanf("%d", &amp;n);
    int a[n];
    for (i=0; i&lt;n; i++) {
      scanf("%d", &amp;a[i]);
    }
    for (i=0; i&lt;n; i++) {
      printf("%d ", a[i]);
    }
    return 0;
  }
  </code></pre>
  
  <p>This code works fine.</p>
  
  <p>My question is how this code can work correctly.Isn't it the violation of basic concept of C that array size must be declared before runtime or allocate it using malloc() at runtime.I'm not doing any of these two things,then why it it working properly ?</p>
  
  <p>Solution to my question is variable length arrays which are supported in C99 but if I play aroundmy code and put the statement int a[n];  above scanf("%d,&amp;n); then it's stops working Why is it so.if variable length arrays are supported in C ?</p>