strcpy() is a standard library function in C++ and is used to copy one string to another. In C++ it is present in the <string.h> and <cstring> header files.
char* strcpy(char* dest, const char* src);
Parameters: This method accepts the following parameters:
- dest: Pointer to the destination array where the content is to be copied.
- src: string which will be copied.
Return Value: After copying the source string to the destination string, the strcpy() function returns a pointer to the destination string.
<< str1 <<
<< str3 <<
str1: Hello Geeks!
str2: Hello Geeks!
str3: Copy successful
Time Complexity: O(n)
Auxiliary Space: O(1)
- This function copies the entire string to the destination string. It doesn’t append the source string to the destination string. In other words, we can say that it replaces the content of the destination string with the content of the source string.
- It does not affect the source string. The source string remains the same after copying.
- This function only works with C style strings and not C++ style strings i.e. it only works with strings of type char str; and not string s1; which are created using standard string data type available in C++ and not C.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses
are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!