title: How much memory does calloc actually allocate?
body: <p>The following code when tested, gives output as </p>
  
  <pre><code>1
  0
  0
  2
  0
  </code></pre>
  
  <p>which is amazing because ptr[3], ptr[4] did not have any memory allocation. Although they stored value in them and prints it. I tried the same code for few larger i's in ptr[i] which again compiled successfully and gives result but for very large value of i, of the order of 100000,program get crashed. if calloc() allocates such a large memory on single call then it is not worth effective. So how calloc() works? Where is this discrepancy?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  void main() {
      int * ptr = (int *)calloc(3,sizeof(int));//allocates memory to 3 integer
      int i = 0;
      *ptr = 1;
      *(ptr+3) = 2;//although memory is not allocated but get initialized
      for( i =0 ; i&lt;5 ; ++i){
          printf("%d\n",*ptr++);
      }
  }
  </code></pre>
  
  <p>After that i tried this code which continuously runs without any output</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  void main() {
  int * ptr = (int *)calloc(3,sizeof(int));
  int i = 0;
  *ptr = 1;
  *(ptr+3) = 2;
  //free(ptr+2);
  for( ; ptr!=NULL ;)
  {
      //printf("%d\n",*ptr++);
      i++;
  }
  printf("%d",i);
  }
  </code></pre>