title: Initialize a dynamic array in C
body: <p>How do I achieve the dynamic equivalent of this static array initialization in C?</p>
  
  <pre><code>char c[] = {}; // Sets all members to '\0';
  </code></pre>
  
  <p>In other words, create a dynamic array with all values initialised to the termination character. Is the below method correct? Is there any better method?</p>
  
  <pre><code>str = (char*)malloc(length*sizeof(char));
  memset(str, 0, length);
  </code></pre>
  
  <p>Thanks!</p>