title: Why use malloc() when I can just define a variable-length array?
body: <p>I was reading about creating array dynamically in C. So the proper way as described there was:</p>
  
  <pre><code>int n;
  scanf("%d", &amp;n);
  int *arr = (int*)malloc(n*sizeof(int));
  </code></pre>
  
  <p>But then I thought if I could just do something like this-</p>
  
  <pre><code>int n, i, sum=0;
  scanf("%d", &amp;n);
  int arr[n];
  </code></pre>
  
  <p>And I compiled and ran it without any error. So, my question is why should I use <code>malloc()</code>? Does this have something to do with the old and new C versions?</p>