- The C Standard Library
- C Library - Home
- C Library - <assert.h>
- C Library - <ctype.h>
- C Library - <errno.h>
- C Library - <float.h>
- C Library - <limits.h>
- C Library - <locale.h>
- C Library - <math.h>
- C Library - <setjmp.h>
- C Library - <signal.h>
- C Library - <stdarg.h>
- C Library - <stddef.h>
- C Library - <stdio.h>
- C Library - <stdlib.h>
- C Library - <string.h>
- C Library - <time.h>
- C Standard Library Resources
- C Library - Quick Guide
- C Library - Useful Resources
- C Library - Discussion
- C Programming Resources
- C Programming - Tutorial
- C - Useful Resources
C library function - memcpy()
Description
The C library function void *memcpy(void *dest, const void *src, size_t n) copies n characters from memory area src to memory area dest.
Declaration
Following is the declaration for memcpy() function.
void *memcpy(void *dest, const void * src, size_t n)
Parameters
dest − This is pointer to the destination array where the content is to be copied, type-casted to a pointer of type void*.
src − This is pointer to the source of data to be copied, type-casted to a pointer of type void*.
n − This is the number of bytes to be copied.
Return Value
This function returns a pointer to destination, which is str1.
Example
The following example shows the usage of memcpy() function.
#include <stdio.h> #include <string.h> int main () { const char src[50] = "https://www.tutorialspoint.com"; char dest[50]; strcpy(dest,"Heloooo!!"); printf("Before memcpy dest = %s\n", dest); memcpy(dest, src, strlen(src)+1); printf("After memcpy dest = %s\n", dest); return(0); }
Let us compile and run the above program that will produce the following result −
Before memcpy dest = Heloooo!! After memcpy dest = https://www.tutorialspoint.com
string_h.htm
Advertisements