1 function prototypes
void *memcpy (void *dest, const void *SRC, size_t n); 2 features copies n bytes from the starting position of the memory address referred to by the source SRC to the beginning of the memory address referred to by the target dest 3 required header files use # include <string.h>; in C languageYou can use # include <cstring> and # include <string.h> in C + +. 4 return value The function returns a pointer to Dest. 5 Description The memory areas referred to by 1.source and Destin may overlap, but if the memory areas referred to by source and Destin overlap, this function does not ensure that the overlapping area of the source is not overwritten before the copy. The use of memmove can be used to process overlapping areas. function returns a pointer to the DestinPointers.2. If the target array Destin itself already has data, after executing memcpy (), the original data will be overwritten (up to N). If you want to append data, add the destination array address to the address you want to append the data to after each execution of memcpy. Note: Both source and Destin are not necessarily arrays, and any readable and writable space is available. its function is implemented as follows:
<span style= "FONT-SIZE:18PX;" > #include <stdio.h> #include <assert.h>void *my_memcopy (void *str1,void const *str2,int len) {char *tmp1= (char*) Str1;char *tmp2= (char*) str2;void *ret=str1;assert (str1); ASSERT (STR2); while (len--) {*tmp1++ = *tmp2++; } return ret;} int main () {char q[] = "Abcdjgfjjyty"; char p[] = "DDDDDDD";//bbit-tehmy_memcopy (q,p,6);p rintf ("%s\n", My_memcopy (q,p,6) ); return 0;} </span>
Results:
Implementation of "C language" memcpy function