title: GCC - memcpy automatically copies null character?
body: <p>From <a href="http://www.cplusplus.com/reference/clibrary/cstring/memcpy/" rel="nofollow">cplusplus.com</a> about <code>memcpy</code>: "The function does not check for any terminating null character in source - it always copies exactly num bytes."</p>
  
  <p>So the following code should give a runtime error, isn't it?</p>
  
  <pre><code>char str1[20] = "";
  char str2[20] = "Another Text---";
  
  memcpy(str1, str2, strlen(str2));
  printf("%s\n%s", str1, str2);
  </code></pre>
  
  <p>But I am always getting the correct output from this code with my gcc compiler. Does this mean memcpy actually copying the null character from the end of <code>str2</code> or it's just a random case?</p>
  
  <p><strong>EDIT:</strong> I get the same behavior with <code>str1[20] = "A"</code>, as some answers are pointing out that <code>str1[20] = ""</code> is initializing the string with all NULL characters.</p>