• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
July 14, 2022 |8.1K Views
C Program to Concatenate Two Strings
  Share  1 Like
Description
Discussion

In this video, we will learn how to Concatenate Two Strings in C.

Examples:
Input String 1: GEEKSFOR
Input String 2: GEEKS
Output String: GEEKSFORGEEKS

Input String 1: HELLO
Input String 2: WORLD!!
Output: HELLO WORLD!!

Here we see different methods for string concatenation:
1. Using while loop
2. Using strcat()

Using while loop: Here we use a while loop that concatenates two strings by repeatedly copying the first string to the end of the second. The first string is terminated by a NULL character. 

Using strcat(): In C, strcat() is a predefined function used for string handling, under the string library (string.h in C). It appends the string pointed to by the source to the end of the string pointed to by the destination. It will append a copy of the source string in the destination string plus a terminating Null character. 

The initial character of the string(src) overwrites the Null-character present at the end of the string(dest).

C Program to Concatenate two strings: https://www.geeksforgeeks.org/c-program-to-concatenate-two-strings-without-using-strcat/

Read More