Home » C Programs » Strcpy Program in C

Strcpy Program in C

Using this program we can copy the value of the variable in the c program which is stored in the variable. strcpy() is a C/C++ standard library function for copying one string to another. It can be found in the string.h header file in C and the cstring header file in C++.

Strcpy Function in C

To copy strings, use the strcpy() function. It copies the string specified by source into the destination. This function takes two pointer to char or array of characters arguments and returns a pointer to the first string that is destination.

The strcpy() function is a standard library function. It is used to copy a string from one location to another. In C, it is declared in the “string. h” header file, whereas in C++, it is declared in the “cstring” header file. It returns the destination pointer. Here we have executed the string copy function in c

Char in C Program

To store characters and letters, c employs the char type. However, the char type is an integer type because c stores integer numbers rather than characters. Char values in C are stored in 1 byte of memory and have a value range of -128 to 127 or 0 to 255.

String in C

In C, a string is simply a collection of characters in a linear sequence. Even if a string contains whitespaces, ‘C’ always treats it as a single data point. The length(string) function is the most basic example of a string function. The length of a string literal is returned by this function. Using this program we can execute strcpy program in c

Array Concept in C Program

An array is defined as a collection of data items of the same type that are stored in contiguous memory locations. Arrays are derived data types in the C programming language that can store primitive data types such as int, char, double, float, and so on.

Strcpy Program in C

//strcpy program in c
int main()
char s1[10], s2[10];
strcpy(s1, "noteshippo.com"); 
strcpy(s2, s1); 
printf("%s\n", s2);