memcpy 和 memmove 有什么区别?

memcpy 和 memmove 有什么区别?

memcpy和memmove都是将源地址的若干个字符拷贝到目标地址。
如果源地址和目标地址有重叠,则memcpy不能保证拷贝正确,但memmove可以保证拷贝正确。 

例如:
char src[20];
// set src
char* dst = src + 5;
此时如果要从src拷贝10个字符到dst,则么memcpy不能保证拷贝正确,但是memmove可以保证


memcpy copies count bytes from src to dest; wmemcpy copies count wide characters (two bytes). If the source and destination overlap, the behavior of memcpy is undefined. Use memmove to handle overlapping regions.


Copies count bytes (wmemmove) or characters (wmemmove) from src to dest. If some regions of the source area and the destination overlap, both functions ensure that the original source bytes in the overlapping region are copied before being overwritten.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值