memmove function
C
Function
Reference manual
@see man memmove, memcpy function
The memmove
function copies n
bytes from the memory area pointed to by src
to the memory area pointed to by dest
.
Unlike memcpy, in memmove the memory areas may overlap so it is generally better to use memmove over memcpy.
Syntax
void *memmove(void *dest, const void *src, size_t n);
Parameters
- dest: A pointer to the destination memory area.
- src: A pointer to the source memory area.
- n: The number of bytes to be copied.
Return value
Returns a pointer to the destination memory area dest
.
Example
In the following example we use the memmove
function to copy the string “memmove can handle overlapping areas.” starting on position 14 to the same memory area starting on position 20, that is two overlapping memory areas.
#include <stdio.h>
#include <string.h>
int main(void) {
char str[] = "memmove can handle overlapping areas.";
memmove(str + 20, str + 14, 10);
printf("%s\n", str);
return (0);
}