 
 Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
strcpy() in C/C++
The function strcpy() is a standard library function. It is used to copy one string to another. In C language,it is declared in “string.h” header file while in C++ language, it is declared in cstring header file. It returns the pointer to the destination.
Here is the syntax of strcpy() in C language,
char* strcpy(char* dest, const char* src);
Some key points of strcpy().
- It copies the whole string to the destination string. It replaces the whole string instead of appending it. 
- It won’t change the source string. 
Here is an example of strcpy() in C language,
Example
#include <stdio.h>
#include<string.h>
int main() {
   char s1[] = "Hello world!";
   char s2[] = "Welcome";
   printf("String s1 before: %s\n", s1);
   strcpy(s1, s2);
   printf("String s1 after: %s\n", s1);
   printf("String s2 : %s", s2);
   return 0;
}
Output
String s1 before: Hello world! String s1 after: Welcome String s2 : Welcome
Advertisements
                    