Library Function strcat in String Class
Library Function strcat of string.h Header File
On this page we will discuss about library function strcat in string class which is used in C.The C header file string.h contains a set of functions that can be used for performing various manipulation operations on strings. The strcat function is used to join or to concatenate the two strings.
Library Function strcat in String Class used in C
In C programming language the strcat function is included in string.h header file.
The function appends the source string to the end of the destination string, overwriting the null character at the end of the destination string and adding a new null character at the end of the resulting concatenated string.
Declaration of strcat function
char *strcat(char *destination, const char *source)
strcat(destination,source);
Parameters of strcat function
The strcat function accepts two parameters which are source and destination.
Parameter | Description |
---|---|
source | It is a pointer to the source string that needs to be concatenated to the destination string. |
destination | It is a pointer to the destination string which will be modified by the source string. |
Return value of strcat function
Implementation of Library Function string.h strcat
Example 1:
#include <stdio.h> #include <string.h> int main() { // Initializing the two strings char destination[20] = "PrepInsta"; char source[10] = " Prime"; // Concatenating the source string to the destination string char *result = strcat(destination, source); // Displaying the resultant string printf("Result: %s\n", result); return 0; }
Output:
Result: PrepInsta Prime
Example 2:
#include <stdio.h> #include <string.h> int main() { // Initialization of multiple strings char destination[50] = " "; char source1[10] = "PrepInsta"; char source2[10] = " Prime"; char source3[10] = " "; // Concatenating the source string to the destination string strcat(destination, source1); strcat(destination, source2); strcat(destination, source3); // Displaying the resultant string printf("%s\n", destination); return 0; }
Output:
PrepInsta Prime
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
Login/Signup to comment