The strcat() function will append a copy of the source string to the end of destination string. The strcat() function takes two arguments:
It will append copy of the source string in the destination string. The terminating character at the end of dest is replaced by the first character of src .
Return value: The strcat() function returns dest, the pointer to the destination string.
This is an example
The strncat() function in C++ appends the given number of character from one string to the end of another string.The strncat() function will take these three arguments:
This will append the given number of characters from src string to the end of dest string. The terminating character at the end of dest string will be replaced by the first character of src string .
Return value: The strncat() function returns dest, the pointer to the destination string.
This is an example to show working of strncat()
How strncat() is different from strcat() ?
It is recommended by many of the programmers that strncat() is safe as compared to strcat() because strcat() does not check for the size of the copied data, and copies until it gets to a null terminator, it might cause a buffer overflow while strncat() check for the size of the copied data, and will copy only ‘n’ bytes.
Before strcat() function execution, destination string : geeks After strcat() function execution, destination string : geeksforgeeks Before strncat() function execution, destination string : geeks After strncat() function execution, destination string : geeksfor
This article is contributed by Pranav. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- strncat() function in C/C++
- Write one line functions for strcat() and strcmp()
- Difference between Sentinel and Counter Controlled Loop in C
- Bitonic string
- Check given string is oddly palindrome or not | Set 2
- Why do we need reference variables if we have pointers
- What are the differences between C and Embedded C?
- Similarities and Difference between Java and C++
- Macros and its types in C/C++
- How to find index of a given element in a Vector in C++
- Introduction to Complex Objects and Composition
- Draw a smiley face using Graphics in C language
- NULL undeclared error in C/C++ and how to resolve it
- Draw a Chess Board using Graphics Programming in C
Improved By : Akanksha_Rai