In C, strcat is a public method for manipulating string data, defined by stringh Yes, the specific functions of which are:Concatenate two strings into a new string and return it
The declared prototype of the strcat method is ,char *strcat(char *_s1, const char *_s2)。From the declaration prototype of the method, it can be seen that the strcat method can only concatenate two strings at a time, and the two strings that need to be concatenated together are passed into the strcat method as parameters.
An example of the use of the strcat method is as follows:
Actually, in stringh, there is also a strncat method with an advanced feature of specifying the number of characters to be concatenated, which declares the prototype aschar *strncat(char *_s1, const char *_s2, size_t __n)。Compared with the strcat method, the strncat method has a third parameter, and this more parameter is used to specify the number of concatenated characters, and by declaring the prototype, we can know that this third parameter has no default value, so it is a required parameter, and its usage example is as follows:
In j**a and python, strings can be concatenated with the + operator, as follows:
However, this string concatenation operation can also be done in C, but the variable type must be declared as string, otherwise it is not supported, as follows:
As you can see from the above, char arrays and string objects have significant functional differences, although they are both strings in form. The reason why the String object in C supports concatenating two String objects with the + operator is because the String class overloads the + operator.