On Friday 10 March 2006 06:36, novice opined (in
<11**********************@j52g2000cwj.googlegroups .com>):
Please explain with an example whts the
DIFFERENCE between "memcpy" and "memmove"
Smells like homework assignment. Make an effort, and DIY.
Here's one: "memcpy" is a string literal that takes 6 bytes (one for
each letter, and one for terminating '\0'), and "memmove" takes 7.
And here's what the Standard has to say about the functions that go by
the names of `memcpy` and `memmove`:
7.21.2.1 The memcpy function
Synopsis
#include <string.h>
void *memcpy(void * restrict s1,
const void * restrict s2,
size_t n);
Description
The memcpy function copies n characters from the object pointed to by
s2 into the object pointed to by s1. If copying takes place between
objects that overlap, the behavior is undefined.
Returns
The memcpy function returns the value of s1.
7.21.2.2 The memmove function
Synopsis
#include <string.h>
void *memmove(void *s1, const void *s2, size_t n);
Description
The memmove function copies n characters from the object pointed to by
s2 into the object pointed to by s1. Copying takes place as if the n
characters from the object pointed to by s2 are first copied into a
temporary array of n characters that does not overlap the objects
pointed to by s1 and s2, and then the n characters from the temporary
array are copied into the object pointed to by s1.
Returns
The memmove function returns the value of s1.
In short, use `memmove` when you're not sure that the memory regions do
not overlap. You can surely come up with an example yourself.
(Also, no need to SHOUT at us.)
--
BR, Vladimir
Langsam's Laws:
(1) Everything depends.
(2) Nothing is always.
(3) Everything is sometimes.