Professional Documents
Culture Documents
Tutorials
Student
Jobs
Courses
Write
Come write articles for us and get featured
Practice
Learn and code with the best industry experts
Premium
Get access to ad-free content, doubt assistance and more!
Jobs
Come and find your dream job with us
o Geeks Digest
o Quizzes
o Geeks Campus
o Gblog Articles
o IDE
o Campus Mantri
My Profile Edit Profile
Logout
Home
Courses
o Practice DS & Algo.
o Algorithms
o Analysis of Algorithms
o Data Structures
o Interview Corner
o Languages
o ISRO CS
o GATE
o CS Subjects
o Web Technologies
o School Learning
o Mathematics
o Maths Notes (Class 8-11)
o NCERT Solutions
o RD Sharma Solutions
o UGC NET CS
o Student
o Jobs
GBlog
Puzzles
What's New ?
Change Language
Related Articles
Related Articles
A shorthand array notation in C for repeated values
Accessing array out of bounds in C/C++
strcpy in C/C++
strcmp() in C/C++
Comparing two strings in C++
std::string::compare() in C++
Comparator function of qsort() in C
std::sort() in C++ STL
What are the default values of static variables in C?
Understanding “volatile” qualifier in C | Set 2 (Examples)
Const Qualifier in C
Initialization of static variables in C
Understanding “register” keyword in C
Understanding “extern” keyword in C
Storage Classes in C
Static Variables in C
Memory Layout of C Programs
How to deallocate memory without using free() in C?
Difference Between malloc() and calloc() with Examples
Dynamic Memory Allocation in C using malloc(), calloc(), free() and realloc()
How to dynamically allocate a 2D array in C?
How to pass a 2D array as a parameter in C?
Multidimensional Arrays in C / C++
2D Vector In C++ With User Defined Size
Vector of Vectors in C++ STL with Examples
What is Memory Leak? How can we avoid?
Arrays in C/C++
Bitwise Operators in C/C++
strcpy in C/C++
Difficulty Level : Easy
Last Updated : 21 Jan, 2021
strcpy() is a standard library function in C/C++ and is used to copy one string to
another. In C it is present in string.h header file and in C++ it is present
in cstring header file.
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.
Below program explains different usages of this library function:
// C program to illustrate
#include<stdio.h>
#include<string.h>
int main ()
char str3[40];
char str4[40];
strcpy(str2, str1);
strcpy(str4, str5);
return 0;
Output:
str1: Hello Geeks!
str2: Hello Geeks!
str3: Copy successful
str4: GfG
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 destination string by the content of source string.
It does not affect the source string. The source string remains 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.
This article is contributed by Harsh Agarwal. If you like GeeksforGeeks and would
like to contribute, you can also write an article using contribute.geeksforgeeks.org or
mail your article to contribute@geeksforgeeks.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.
Want to learn from the best curated videos and practice problems, check out the C
Foundation Course for Basic to Advanced C.
Like37
Previous
Accessing array out of bounds in C/C++
Next
strcmp() in C/C++
ADVERTISEMENT BY ADRECOVER
RECOMMENDED ARTICLES
Page :
1
2
28, Nov 17
03, Aug 18
22, Jul 21
Implementing Sets Without C++ STL Containers
20, Jul 21
20, Jul 21
20, Jul 21
20, Jul 21
19, Jul 21
Article Contributed By :
GeeksforGeeks
Vote for difficulty
Improved By :
oliverelarsen
CoderSaty
Article Tags :
C-String
cpp-string
C Language
C++
Practice Tags :
CPP
Improve Article
Report Issue
ADS BY ADRECOVER
WHAT'S NEW
View Details
DSA Self Paced Course
View Details
View Details
ADS BY ADRECOVER
Writing code in comment? Please use ide.geeksforgeeks.org, generate link and share the link here.
Load Comments
ADVERTISEMENT BY ADRECOVER