String concatenation in Data Structure using C

In C, we can concatenate two strings using the `strcat()` function. Here's an example:

```
#include <stdio.h>
#include <string.h>

int main() {
    char str1[100] = "Hello, ";
    char str2[100] = "world!";

    strcat(str1, str2);

    printf("Concatenated string: %s\n", str1);

    return 0;
}
```

In this program, we first declare two character arrays `str1` and `str2`. We initialize `str1` with the string "Hello, " and `str2` with the string "world!". We then use the `strcat()` function to concatenate `str2` to the end of `str1`. Finally, we print the concatenated string using `printf()`.


Note that the `strcat()` function modifies the first string by appending the second string to the end of it. The second string remains unchanged. Also, make sure that the first string has enough space to accommodate the concatenated string, including the null character (`\0`) at the end.



About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc





 PreviousNext