Difference b/t memmove and memcpy

Difference between memmove and memcpy ?

void *memcpy(void *restrict s1, const void *restrict s2, size_t n);

The  memcpy() function copies n bytes from memory area s2 to s1. It returns s1. If copying takes  place  between  objects that overlap, the behavior is undefined.

void *memmove(void *s1, const void *s2, size_t n);

The memmove() function copies n bytes from memory area s2 to memory area s1. Copying between objects  that  overlap  will take place correctly. It returns s1.

What is this overlapping of objects?

#include <stdio.h>
#include <string.h>

main()

{

char string1[30]=”Gangadhar Mylapuram”;
char string2[30]=”Gangadhar Mylapuram”;
char *s1;
s1= string1 + 1;

memcpy(s1,string1,5);
printf(“memcpy: %s string %s\n”,s1,string1);

s1= string2 + 1;
memmove(s1,string2,5);
printf(“memmove: %s string %s\n”,s1,string2);

}

}

memcpy: Gangghar Mylapuram string GGangghar Mylapuram
memmove: Gangahar Mylapuram string GGangahar Mylapuram

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s