函数
头文件<cstring>
memcpy
void * memcpy ( void * 目标, const void * 源, size_t num(字节大小) );
拷贝整块的内存
拷贝num字节的数据从源到目标指针指向的内存块
这种对象的底层要求源和目标的指针是不同的,拷贝的结果是二进制
这个函数不会检查源中的终止标志,总是拷贝num个字节为了避免溢出,num的大小应该是源和目标的大小的最小值,并且两者不应重叠
Parameters
-
destination
- Pointer to the destination array where the content is to be copied, type-casted to a pointer of type void*. source
- Pointer to the source of data to be copied, type-casted to a pointer of type const void*. num
-
Number of bytes to copy.
size_t is an unsigned integral type.
Return Value
destination is returned.Example
| |
|
Output:
person_copy: Pierre de Fermat, 46 |
See also
-
memmove
- Move block of memory (function )
-
memchr
- Locate character in block of memory (function )
-
memcmp
- Compare two blocks of memory (function )
-
memset
- Fill block of memory (function )
-
strncpy
- Copy characters from string (function )