VOOZH about

URL: https://www.geeksforgeeks.org/computer-science-fundamentals/concatenation-of-two-strings/

⇱ Concatenation of Two Strings - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Concatenation of Two Strings

Last Updated : 7 Mar, 2026

String concatenation is the process of joining two strings end-to-end to form a single string.

Examples

Input: s1 = "Hello", s2 = "World"
Output: "HelloWorld"
Explanation: Joining "Hello" and "World" results in "HelloWorld".

Input: s1 = "Good", s2 = "Morning"
Output: "GoodMorning"
Explanation: Joining "Good" and "Morning" results in "GoodMorning"

Using '+' Operator - O(n+m) Time and O(n+m) Space

Almost all languages support + operator to concatenate two strings. In C, we have a library function strcat() for the same purpose.


Output
Hello, World!

Write your Own Method - O(n+m) Time and O(n+m) Space

  • Create an empty result string.
  • Traverse through s1 and append all characters to result.
  • Traverse through s2 and append all characters to result.

Output
Hello, World!
Comment
Article Tags: