title: Why calloc works only in specific parts of the code?
body: <p>Why the first code works fine, while the second one doesnt? The only difference is where I place <code>calloc</code> in the secondary function. The reason I ask is I would have thought that the second code is the one to work, considering the value of <code>divisor_number</code> is only known once I do the for loop in the secondary function. Could you give me a quick explanation on this one? Thank you!</p>
  
  <p>Also, I am not getting any errors or warnings when running the second code. Is there a way I could get some additional information from the compiler to lead me in the right direction? Thank you!</p>
  
  <p><strong>N.b.</strong> Apologies for the code not being very organised from a logical stand point, just working on it to get a better grasp of a few programming concepts.</p>
  
  <p>1st code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;locale.h&gt;
  
  
  int* save_number(int *int_number);
  
  int main()
  {
     int int_number, *divisors = 0, count_even, i;
  
     printf("Please enter an integer:");
     divisors = save_number(&amp;int_number);
  
     for (i = 1; i &lt;= int_number; ++i)
     {
        if (divisors[i-1] % 2 == 0 &amp;&amp; divisors[i-1] != 0)
        {
           printf("%d\n", divisors[i-1]);
           count_even++;
        }
        continue;
     }
     printf("Total even divisors: ");
     printf("%d\n", count_even);
     return 0;
  }
  
  int* save_number(int *int_number)
  {
     int i, *divisors = 0, divisor_number;
     divisors = calloc(divisor_number, sizeof *divisors);
  
     scanf("%d", int_number);
  
     for (i = 1; i &lt;= *int_number; ++i)
     {
        if (*int_number % i == 0)
        {
           divisors[i-1] = i;
           printf("%d\n", divisors[i-1]);
           divisor_number++;
        }
        continue;
     }
  
     return divisors;
  }
  </code></pre>
  
  <p>2nd code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;locale.h&gt;
  
  
  int* save_number(int *int_number);
  
  int main()
  {
     int int_number, *divisors = 0, count_even, i;
  
     printf("Please enter an integer:");
     divisors = save_number(&amp;int_number);
  
     for (i = 1; i &lt;= int_number; ++i)
     {
        if (divisors[i-1] % 2 == 0 &amp;&amp; divisors[i-1] != 0)
        {
           printf("%d\n", divisors[i-1]);
           count_even++;
        }
        continue;
     }
     printf("Total even divisors: ");
     printf("%d\n", count_even);
     return 0;
  }
  
  int* save_number(int *int_number)
  {
     int i, *divisors = 0, divisor_number;
     scanf("%d", int_number);
  
     for (i = 1; i &lt;= *int_number; ++i)
     {
        if (*int_number % i == 0)
        {
           divisors[i-1] = i;
           printf("%d\n", divisors[i-1]);
           divisor_number++;
        }
        continue;
     }
     divisors = calloc(divisor_number, sizeof *divisors);
     return divisors;
  }
  
  </code></pre>