Interview Question

Difference between memcpy and memmove?

Use memmove for overlapping regions; memcpy requires no overlap.

💡 Concept ✅ Quick Revision ⚙ C

Answer

memcpy and memmove copy a specified number of characters between objects. • memcpy requires source and destination regions not to overlap. • memmove behaves as if it first copies through a temporary array, so overlap is supported. • Both functions require valid regions large enough for the requested byte count.

💡 C Example

char text[] = "ABCDE"; memmove(text + 1, text, 4); text[5] = '\0'; printf("%s\n", text);

Output

AABCD

⚡ Quick Revision

Use memmove for overlapping regions; memcpy requires no overlap.