Home > Backend Development > C++ > In C/C++, the strcpy() function is a function used to copy one string to another string

In C/C++, the strcpy() function is a function used to copy one string to another string

WBOY
Release: 2023-09-09 08:49:02
forward
983 people have browsed it

In C/C++, the strcpy() function is a function used to copy one string to another string

The function strcpy() is a standard library function. It is used to copy one string to another string. In C language, it is declared in the "string.h" header file, while in C language, it is declared in the cstring header file. It returns a pointer to the destination.

This is the syntax of strcpy() in C language,

char* strcpy(char* dest, const char* src);
Copy after login

Some key points of strcpy().

  • It copies the entire string into the target string. It replaces the entire string instead of appending it.

  • It does not change the source string.

The following is an example of strcpy() in C language:

Example

Online demonstration

#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;
}
Copy after login

Output

String s1 before: Hello world!
String s1 after: Welcome
String s2 : Welcome
Copy after login

The above is the detailed content of In C/C++, the strcpy() function is a function used to copy one string to another string. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template