
- The C Standard Library
- C Library - Home
- C Library - <assert.h>
- C Library - <ctype.h>
- C Library - <errno.h>
- C Library - <float.h>
- C Library - <limits.h>
- C Library - <locale.h>
- C Library - <math.h>
- C Library - <setjmp.h>
- C Library - <signal.h>
- C Library - <stdarg.h>
- C Library - <stddef.h>
- C Library - <stdio.h>
- C Library - <stdlib.h>
- C Library - <string.h>
- C Library - <time.h>
- C Standard Library Resources
- C Library - Quick Guide
- C Library - Useful Resources
- C Library - Discussion
- C Programming Resources
- C Programming - Tutorial
- C - Useful Resources
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C library function - memmove()
Description
The C library function void *memmove(void *str1, const void *str2, size_t n) copies n characters from str2 to str1, but for overlapping memory blocks, memmove() is a safer approach than memcpy().
Declaration
Following is the declaration for memmove() function.
void *memmove(void *str1, const void *str2, size_t n)
Parameters
str1 − This is a pointer to the destination array where the content is to be copied, type-casted to a pointer of type void*.
str2 − This is a pointer to the source of data to be copied, type-casted to a pointer of type void*.
n − This is the number of bytes to be copied.
Return Value
This function returns a pointer to the destination, which is str1.
Example
The following example shows the usage of memmove() function.
#include <stdio.h> #include <string.h> int main () { char dest[] = "oldstring"; const char src[] = "newstring"; printf("Before memmove dest = %s, src = %s\n", dest, src); memmove(dest, src, 9); printf("After memmove dest = %s, src = %s\n", dest, src); return(0); }
Let us compile and run the above program that will produce the following result −
Before memmove dest = oldstring, src = newstring After memmove dest = newstring, src = newstring
string_h.htm
Advertisements