Memmove function in C

Void function * memmove (void * str1, const void * str2, size_t n) Copy n characters from str2 to str1, but to solve the matching of memory blocks, memmove () is a safe approach more than memcpy ().

Void function * memmove (void * str1, const void * str2, size_t n) Copy n characters from str2 to str1, but to solve the matching of memory blocks, memmove () is a safe approach more than memcpy ().

Declare memmove function in C

Below is the declaration for memmove () in C:

 void * memmove ( void * str1 , const void * str2 , size_t n ) 

Parameters

str1 - This is the pointer to the destination array, where the content to be copied, cast into a pointer of type void *.

str2 - This is the pointer to the data source to copy, cast into a pointer of type void *.

n - This is the number of bytes to be copied.

Returns the value

This function returns a pointer to the destination string, str1.

For example

The following program C illustrates the usage of memmove () in C:

 #include #include int main () { char str [] = "Vi du ham memmove trong C" ; memmove ( str + 20 , str + 15 , 11 ); puts ( str ); return 0 ; } 

Compiling and running the above C program will result:

Memmove function in C Picture 1Memmove function in C Picture 1

According to Tutorialspoint

Last lesson: Function memcpy () in C

Next lesson: memset () function in C

4.5 ★ | 6 Vote