strcpy in C++ Last Updated : 11 Jan, 2025 Comments Improve Suggest changes Like Article Like Report 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. Syntax: 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.The strcpy() function is used to copy strings in C++. Example: C++ // C++ program to illustrate // strcpy() function in C/C++ #include <iostream> #include <cstring> using namespace std; int main() { // Strings Declared char str1[] = "Hello Geeks!"; char str2[] = "GeeksforGeeks"; char str3[40]; char str4[40]; char str5[] = "GfG"; // String copy used strcpy(str2, str1); strcpy(str3, "Copy successful"); strcpy(str4, str5); // Strings Printed cout << "str1: " << str1 << "\nstr2: " << str2 << "\nstr3: " << str3 << "\nstr4: " << str4; return 0; } Outputstr1: Hello Geeks! str2: Hello Geeks! str3: Copy successful str4: GfGTime Complexity: O(n)Auxiliary Space: O(1)Important Points: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. Function to copy string - strcpy implementation Comment More infoAdvertise with us K kartik Follow Improve Article Tags : C++ cpp-string Practice Tags : CPP Explore Introduction to C++Introduction to C++ Programming Language3 min readHeader Files in C++5 min readSetting up C++ Development Environment8 min readDifference between C and C++3 min readBasicsC++ Data Types7 min readC++ Variables4 min readOperators in C++9 min readBasic Input / Output in C++5 min readControl flow statements in Programming15+ min readC++ Loops7 min readFunctions in C++8 min readC++ Arrays8 min readStrings in C++5 min readCore ConceptsPointers and References in C++5 min readnew and delete Operators in C++ For Dynamic Memory5 min readTemplates in C++8 min readStructures, Unions and Enumerations in C++3 min readException Handling in C++11 min readFile Handling through C++ Classes8 min readMultithreading in C++8 min readNamespace in C++5 min readC++ OOPInheritance in C++10 min readC++ Polymorphism5 min readEncapsulation in C++4 min readAbstraction in C++4 min readStandard Template Library(STL)Containers in C++ STL3 min readIterators in C++ STL10 min readC++ STL Algorithm Library2 min readPractice C++C++ Interview Questions and Answers (2025)15+ min readTop C++ DSA Related ProblemsC++ Programming Examples7 min read Like