Prototype
Declared in string.h
In C90, the prototype is:
void *memcpy(void *dest, const void *src, size_t n);
In C99, the prototype is:
void *memcpy(void * restrict dest, const void * restrict src, size_t n);
Description
The memcpy() function shall copy the first n bytes pointed to by src to the buffer pointed to by dest. Source and destination may not overlap.
If source and destination might overlap, memmove() must be used instead.
Return value
The memcpy() function shall return the pointer dest; the function has no failure mode and no error return.
Implementation
In standard C, this can be implemented as (adjust prototype for C99):
#include <stddef.h> /* size_t */ void *memcpy(void *dest, const void *src, size_t n) { char *dp = dest; const char *sp = src; while (n--) *dp++ = *sp++; return dest; }
Compilable unit, portable C90 in implementation namespace; public domain; past reviewers: none; current reviews: none
References
The C Standard, 7.21.2.1 (C99 numbering)