memcpy() in C/C++
memcpy() is used to copy a block of memory from a location to another. It is declared in string.h
// Copies "numBytes" bytes from address "from" to address "to" void * memcpy(void *to, const void *from, size_t numBytes);
Below is a sample C program to show working of memcpy().
str1 before memcpy Geeks str1 after memcpy Quiz
1) memcpy() doesn’t check for overflow or \0
2) memcpy() leads to problems when source and destination addresses overlap.
memmove() is another library function that handles overlapping well.
Write your own memcpy() and memmove()
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
My Personal Notes arrow_drop_up
Please Login to comment...