memcpy() and memmove() from the string.h Library

You can't assign one array to another, so we've been using loops to copy one array to another element by element. The one exception is that we've used the strcpy() and strncpy() functions for character arrays. The memcpy() and memmove() functions offer you almost the same convenience for other kinds of arrays. Here are the prototypes for these two functions:

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

Both of these functions copy n bytes from the location pointed to by s2 to the location pointed to by s1, and both return the value of s1. The difference between the two, as indicated by the keyword restrict, is that

Get C Primer Plus, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.