C memmove() Function

You are Here:

C memmove() Function

The memmove() function copies a block of memory from a location to another.

This function copies the data first to an intermediate buffer, then from buffer to destination. So, memmove() is slightly slower approach than memcpy().

This function doesn't overlap the source. So, memmove() is safer than memcpy().


C Compiler
#include <stdio.h> #include <string.h> int main() { char dest[] = "abcde"; char src[] = "123"; memmove(dest, src, 3); printf("New dest = %s", dest); return 0; }


New dest = 123de


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

Parameter Values

destRequiredDestination array where the content is to be copied.
srcRequiredSource of data to be copied.
nRequiredNumber of bytes to be copied.

Return Value

AddressReturns a pointer to the destination, which is dest array.

More Examples

In the following example, the destination string is "cde" and the source string is "abcde". So, the memmove() function will replace "cde" with "abc" and the result is ababc.


C Compiler
#include <stdio.h> #include <string.h> int main() { char str1[] = "abcde"; memmove(&str1[2], &str1[0], 3); printf("New str1 = %s", str1); return 0; }


New str1 = ababc

In the following example, memcpy() overlaps the source, but memove() doesn't.


C Compiler
#include <stdio.h> #include <string.h> int main() { char str1[] = "abcde"; char str2[] = "abcde"; memmove(&str1[2], &str1[0], 3); memcpy(&str2[2], &str2[0], 3); printf("memmove's str1 = %s\n", str1); printf("memcpy's str2 = %s\n", str2); return 0; }


memmove's str1 = ababc memcpy's str2 = ababc


Hi Developers, we almost covered 98% of String functions and Interview Question on C with examples for quick and easy learning.

We are working to cover every Single Concept in C.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author