CS 3 (Spring 2023) memmove

Name

memmove - copy memory area

Synopsis

#include <string.h>

void *memmove(void *dest, const void *src, size_t n);

Description

The memmove() function copies n byes from memory area src to memory area dest. The memory areas may overlap: copying takes place as though the bytes in src are first copied into a temporary array that does not overlap src or dest, and the bytes are then copied from the temporary array to dest.

Example

#include <assert.h>
#include <string.h>

int main() {
    char src[6] = "hello";
    char dest[6];

    // Copy six bytes/chars, five letters plus null character. 
    memmove(dest, src, 6);
    assert(strcmp(src, dest) == 0)  
}

Return Value

Upon completion, the memmove() function returns a pointer to dest.

See Also

memcpy(), strcpy(), strncpy(), strcmp()