The difference between the usage of memcpy and strcpy and the realization of pure C language

Source: Internet
Author: User

void * memcpy (void* destination, const void * source, size_t num);

function function:

The memory area referred to by source replicates Num bytes to the memory area referred to by destination.

function returns:

A pointer to the destination.

1 memcpy you can copy arbitrary content, such as character arrays, integers, structs, classes, and so on.

2 memcpy according to its first 3 parameters determine the length of the copy, strcpy does not need to specify a length, it encounters a string terminator " the" will end.

3 typically used when copying a string strcpy , while other types of data need to be replicated memcpy .

void* _memcpy (void *des, const void *SCR, size_t n) {void *res=des;assert (des!=null&&scr!=null);//This will void* Cast to char* type while (n--) {* ((char *) des) ++=* ((char *) SCR) + +;} return res;}


The difference between the usage of memcpy and strcpy and the realization of pure C language

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.