Q16 What is the difference between memcpy and memmove.

Hmm friends this is interviewer’s favourite question. Interviewer wants to know, how you handle byte stream.

Prototype of memcpy()

void *memcpy( void  *to, const void *from, size_t n);

memcpy() function is used to copy the block of n bytes pointed by from to the pointed by to and it returns pointer pointed by to. But it does not take care if memory overlap means if source and destination argument overlap.

Prototype of memmove()

void *memmove( void  *to, const void *from, size_t n);

memmove() function is used to copy the block of n bytes pointed by from to the pointed by to and it returns pointer pointed by to. It takes care if memory overlap, so it’s always safe to use memmove().

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.