title: Array of unknown bound usage in C programming
body: <p>I output of below code is undefined when I ran multiple times. I would like to know why the output is undefined and what will be implication when I try to assign value to an array of unknown bound.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main()
  {
    int a[]= {};
    int num_of_elements;
    int count = 0;
  
    printf("Enter the number of elements:\n");
    scanf("%d",&amp;num_of_elements);
  
    printf("Enter the numbers:\n");
    for(count=0; count&lt;num_of_elements; ++count)
    {
      scanf("%d", &amp;a[count]);
    }
    printf("\n");
  
    for(count=0; count&lt;num_of_elements; count++)
    {
      printf("%d,   ", a[count]);
    }
    printf("\n");
  
    return 0;
  }
  </code></pre>
  
  <p>Output when run at different times:</p>
  
  <pre class="lang-none prettyprint-override"><code>Enter the number of elements:
  2
  
  Enter the numbers:
  1 2
  
  0,   0,
  </code></pre>
  
  <hr>
  
  <pre class="lang-none prettyprint-override"><code>Enter the number of elements:
  3
  
  Enter the numbers:
  1 2 3
  
  0,   0,   2,
  </code></pre>
  
  <hr>
  
  <pre class="lang-none prettyprint-override"><code>Enter the number of elements:
  4
  
  Enter the numbers:
  1 2 3 4
  
  0,   0,   2,   3,
  Segmentation fault
  </code></pre>
  
  <hr>
  
  <pre class="lang-none prettyprint-override"><code>Enter the number of elements:
  5
  
  Enter the numbers:
  1 2 3 4 5
  
  0,   0,   2,   3,   4,
  Segmentation fault
  </code></pre>