VOOZH about

URL: https://www.geeksforgeeks.org/c/concatenating-two-strings-in-c/

⇱ Concatenating Two Strings in C - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Concatenating Two Strings in C

Last Updated : 12 Jul, 2025

Concatenating two strings means appending one string at the end of another string. In this article, we will learn how to concatenate two strings in C.

The most straightforward method to concatenate two strings is by using strcat() function. Let's take a look at an example:


Output
Hello Geeks

The strcat() function is specifically designed to concatenate two strings. It appends the second string (source string) to the end of the first string (destination string)

Note: The destination string should have enough space to store the concatenated string. Otherwise, a segmentation fault may occur.

There are also a few other methods in C to concatenate two strings. Some of them are as follows:

Using sprintf()

The sprintf() function is used to print / store a formatted string to a string buffer. It can be used for concatenating two strings by using the source string as formatted string and destination string as string buffer.


Output
Hello Geeks

Using memmove()

The memmove() function can be used to copy the whole block of memory occupied by source string at the end of destination string effectively concatenating the two strings.


Output
Hello Geeks

Note: The memcpy() function can also be used in place of memmove() if the source and destination string does not overlap.

Manually Using a Loop

Use a loop to copy each character of source string at the end of the destination string. The end of the destination string can be found by using strlen() function.


Output
Hello Geeks
Comment