What's the difference in both the code snippets? How does it matter to compiler if I am not telling how many bytes needed for array : <p>The basic program of concatenating two strings. I am not getting the point of how not defining the length of str1 array is leading to core dump.</p>

<p>If I define the length of str1 let's say to str1[100] then the program is working fine. </p>

<pre><code>void myStrcat(char *a, char *b)
{
    int m = strlen(a);
    int n = strlen(b);
    int i;
    for (i = 0; i &lt;= n; i++){
       a[m+i]  = b[i];
    }

}

int main()
{
    char str1[] = "String1 ";
    char *str2 = "String2";
    myStrcat(str1, str2);
    printf("%s ", str1);
    return 0;
}
</code></pre>

<p><strong>* stack smashing detected *</strong>:  terminated
Aborted (core dumped)</p>
