memcpy
Copy memory area
Description
The memcpy function copies len bytes from memory area src to memory area dst. If src and dst overlap, behavior is undefined. Applications in which src and dst might overlap should use reference:memmove instead.Example 1
#include <stdio.h> #include <string.h> int main() { // define two arrays u, v and initialize u int u[5] = {1, 2, 3, 4, 5}, v[5]; // copy u to v memcpy(v, u, 5*sizeof(int)); // display v for (int i = 0; i < 5; ++i) printf("v[%d] = %d\n", i, v[i]); return 0; }
Output:v[0] = 1 v[1] = 2 v[2] = 3 v[3] = 4 v[4] = 5