As far as I could understand, memcpy just iterate through the memory( byte by byte or word by word) and blindly copies 'n' number of bytes from source to destination without considering whether source and destination memory overlaps. While memmove first copies n number of bytes to intermediate buffer and then copies the buffer content to destination address.
consider the following example: #include <cstdio> #include <memory.h> #include <iostream> using namespace std; int main() { char a[20] = "weather is good"; memcpy(a+1, a, strlen(a) ); cout << a; return 0; } it produces the o/p: wweather is good But as per definition of memcpy, o/p should be : wwwwwwwwwwwwwww. Its because, after writing 'w' at a[1], memcpy tries to copy a[1] to a[2] , but now we have 'w' at a[1]. so effectively w should be copied on subsequent locations (from a[2] onwards) strlen(a) times. can anybody explain the o/p "wweather is good" to me? Can you give me an example when just replacing memmove by memcpy produces different output? -- Vipin Delhi College of Engineering -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/QG9qW4hwkloJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.