Differences between memcpy and memmove, and between memcpy and strcpy

Source: Internet
Author: User

The following is the result of man memcpy:

# Include <string. h>

Void * memcpy (void * DEST, const void * SRC, size_t N );

Description
The memcpy () function copies n Bytes from memory area SRC to memory
Area DeST. The memory areas must not overlap. Use memmove (3) if
Memory areas do overlap.

Memcpy and memmove
Memmove is used to handle the overlap between the buckets pointed to by Src and DeST. Therefore, it uses a temporary array to copy SRC to a temporary array, and then copy the temporary array to DeST, in this way, there will be no errors even if there is overlap, which also requires a cost. Therefore, memcpy should be used if there is no overlap.


Memcpy, strcpy

Strcpy is mainly used to copy strings, while memcpy can copy any type. Of course, it doesn't care what type to copy. It is a whole block copy based on memory data. The main difference between the two is that strcpy 'ends with \ 0', while memcpy does not end, so you need to specify the copy size.


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.