title: Confusion in "strcat function in C assumes the destination string is large enough to hold contents of source string and its own."
body: <p>So I read that <code>strcat</code> function is to be used carefully as the destination string should be large enough to hold contents of its own and source string. And it was true for the following program that I wrote:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  int main(){
      char *src, *dest;
      printf("Enter Source String : ");
      fgets(src, 10, stdin);
      printf("Enter destination String : ");
      fgets(dest, 20, stdin);
      strcat(dest, src);
      printf("Concatenated string is %s", dest);
      return 0;
  }
  </code></pre>
  
  <p>But not true for the one that I wrote here:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  int main(){
      char src[11] = "Hello ABC";
      char dest[15] = "Hello DEFGIJK";
      strcat(dest, src);
      printf("concatenated string %s", dest);
      getchar();
      return 0;
  }
  </code></pre>
  
  <p>This program ends up adding both without considering that destination string is not large enough. Why is it so?</p>