title: I'm very confused about malloc() and calloc() on C
body: <p>I've always programmed in Java, which is probably why I'm so confused about this:</p>
  
  <p>In Java I declare a pointer:</p>
  
  <pre><code>int[] array
  </code></pre>
  
  <p>and initialize it or assign it some memory:</p>
  
  <pre><code>int[] array = {0,1,0}
  int[] array = new int[3]
  </code></pre>
  
  <p>Now, in C, it's all so confusing. At first I thought it was as easy as declaring it:</p>
  
  <pre><code>int array[]
  </code></pre>
  
  <p>and initializing it or assigning it some memory:</p>
  
  <pre><code>int array[] = {0,1,0}
  int array[] = malloc(3*sizeof(int))
  int array[] = calloc(3,sizeof(int))
  </code></pre>
  
  <p>Unless I'm wrong, all of the above is equivalent Java-C, right?</p>
  
  <p>Then, today I met a code in which I found the following:</p>
  
  <pre><code>pthread_t tid[MAX_OPS];
  </code></pre>
  
  <p>and some lines below, without any kind of initialization...</p>
  
  <pre><code>pthread_create(&amp;tid[0],NULL,mou_usuari,(void *) 0);
  </code></pre>
  
  <p>Surprisingly (at least to me), the code works! At least in Java, that would return a nice "NullPointerException"!</p>
  
  <p>So, in order:</p>
  
  <ol>
  <li><p>Am I correct with all of the Java-C "translations"?</p></li>
  <li><p>Why does that code work?</p></li>
  <li><p>Is there any difference between using <code>malloc(n*sizeof(int))</code> and <code>calloc(n,sizeof(int))</code>?</p></li>
  </ol>
  
  <p>Thanks in advance</p>