Standards / Extensions | C or C++ | Dependencies |
---|---|---|
ISO C |
both |
#include <string.h>
void *memcpy(void * __restrict__dest, const void * __restrict__src, size_t count);
The memcpy() built-in function copies count bytes from the object pointed to by src to the object pointed to by dest. See Built-in functions for information about the use of built-in functions. For memcpy(), the source characters may be overlaid if copying takes place between objects that overlap. Use the memmove() function to allow copying between objects that overlap.
memcpy() returns the value of dest.
⁄* CELEBM13
This example copies the contents of source to target.
*⁄
#include <string.h>
#include <stdio.h>
#define MAX_LEN 80
char source[ MAX_LEN ] = "This is the source string";
char target[ MAX_LEN ] = "This is the target string";
int main(void)
{
printf( "Before memcpy, target is \"%s\"\n", target );
memcpy( target, source, sizeof(source));
printf( "After memcpy, target becomes \"%s\"\n", target );
}
Before memcpy, target is "This is the target string"
After memcpy, target becomes "This is the source string"