title: Array size based on user input
body: <p>The program I am working on requires the user to enter an integer value and then based on that value print an array of zero's. I have been able to do this when the size of the array is preset however when attempting to do it on a user input I get compiler errors. I have tried researching on a fix however I have come upon nothing since most of the fixes use <code>dynamic memory allocation</code> which we have not yet taught how to use. This is the code I have come up with so far. </p>
  
  <p>In my attempts at finding out why I get errors is that I found if I don't initialise the array with <code>0</code> the array is printed to the size the user inputs however of course the array output numbers are completely random. </p>
  
  <p>When I have the size of the array initialised I get the error <code>variable-sized object may not be initialized</code> with a small arrow pointing to the <code>j</code> within the square brackets in <code>int j, ar[j]={20};</code>. </p>
  
  <p>Is there any other way that doesn't use <code>dynamic memory allocation</code>? </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main(void){
  
      int i;
      int j, ar[j]={0};
  
      printf("Please enter the value:");
      scanf("%d",&amp;j);
  
      for(i=0; i&lt;j;i++){
          printf("%i\n",ar[j]);
      }
  </code></pre>