Size definition of strcat() function

前端 未结 4 1141
既然无缘
既然无缘 2021-01-28 02:25

The question is why should I define size of string (string[] should be string[some-number]) When the program is as following it gives me Abort tr

4条回答
  •  终归单人心
    2021-01-28 02:47

    The first parameter of strcat is used to store the result, so it must have enough space for the concatenated string.

    In your code:

    char buffer1[] = "computer";
    

    is equivalent to:

    char buffer1[9] = "computer";
    

    defines a char array with just enough space for the string "computer", but not enough space for the result.

提交回复
热议问题