• Source
    1. #include <stdio.h>
    2. #include <string.h>
    3.  
    4. int main(void) {
    5. char dest_arr[] = "DDDAAABBB";
    6. // to , from , size
    7.  
    8. printf("length of string is %d \n", strlen(dest_arr));
    9.  
    10. // in case of overlap behavior of memcpy is undefined.
    11. printf("string before memcpy is %s \n", dest_arr);
    12. memcpy( dest_arr + 3, dest_arr, 6);
    13. printf("string after memcpy is %s \n", dest_arr);
    14.  
    15. // retintialising the string.
    16. strcpy(dest_arr, "DDDAAABBB");
    17.  
    18. // note that memmove detects overlap of "AAA" and copy that first.
    19. printf("string before memmove is %s \n", dest_arr);
    20. memmove( dest_arr + 3, dest_arr, 6);
    21. printf("string after memmove is %s \n\n", dest_arr);
    22.  
    23. // use of memset
    24. memset(dest_arr,0x31,strlen(dest_arr));
    25. printf("string after using memset is %s \n\n", dest_arr);
    26. }
    27.