title: Strange behaviour when allocating char**
body: <p>I am trying to create an array of strings and fill it with the character '0' using a function. The code looks like this:</p>
  <pre><code>void    init_array(char **array)
  {
      int i;
      int j;
  
      i = 0;
      while (i &lt; 4)
      {
          array[i] = (char*)malloc(sizeof(char) * 5);
          j = 0;
          while (j &lt; 4)
          {
              array[i][j] = '0';
              array[i][4] = '\0';
              j++;
          }
          i++;
      }
  }
  
  int main(void)
  {
      char **c;
      c = (char**)malloc(sizeof(**c) * 4);
      init_array(c);
      for (int i = 0; i &lt; 4; i++)
          printf(&quot;%s\n&quot;, c[i]);
  }
  </code></pre>
  <p>This prints the array with 0's, except for the first line, which displays weird characters (question marks and such). Strangely, if I change the value of <code>i</code> in the <code>init_array</code> function to <code>-1</code>, then the whole array gets displayed properly. Could anyone please explain what I am doing wrong?</p>