title: calloc v/s malloc and time efficiency
body: <p>I've read with interest the post <a href="https://stackoverflow.com/questions/1538420/c-difference-between-malloc-and-calloc"><em>C difference between malloc and calloc</em></a>. I'm using malloc in my code and would like to know what difference I'll have using calloc instead.</p>
  
  <p>My present (pseudo)code with malloc:</p>
  
  <p><strong>Scenario 1</strong></p>
  
  <pre><code>int main()
  {  
     allocate large arrays with malloc
  
     INITIALIZE ALL ARRAY ELEMENTS TO ZERO
  
     for loop //say 1000 times
      do something and write results to arrays
     end for loop
  
     FREE ARRAYS with free command
  
  } //end main
  </code></pre>
  
  <p>If I use calloc instead of malloc, then I'll have:</p>
  
  <p><strong>Scenario2</strong></p>
  
  <pre><code>int main()
  {  
  
     for loop //say 1000 times
      ALLOCATION OF ARRAYS WITH CALLOC 
  
      do something and write results to arrays
  
      FREE ARRAYS with free command
  
     end for loop
  
  
  } //end main
  </code></pre>
  
  <p>I have three questions:</p>
  
  <ol>
  <li><p>Which of the scenarios is more efficient if the arrays are very large?</p></li>
  <li><p>Which of the scenarios will be more time efficient if the arrays are very large?</p></li>
  <li><p>In both scenarios,I'm just writing to arrays in the sense that for any given iteration in the for loop, I'm writing each array sequentially from the first element to the last element. The important question: If I'm using malloc as in scenario 1, then is it necessary that I initialize the elements to zero? Say with malloc I have array z = [garbage1, garbage2, garbage 3]. For each iteration, I'm writing elements sequentially i.e. in the first iteration I get z =[some_result, garbage2, garbage3], in the second iteration I get in the first iteration I get z =[some_result, another_result, garbage3] and so on, then do I need specifically to initialize my arrays after malloc?</p></li>
  </ol>