目录
memcpy
memcpy:内存拷贝函数
使用内存函数要包含头文件 <string.h> |
void * memcpy ( void * destination, const void * source, size_t num );
destination:目标空间
source:源头
num:要拷贝的字节个数
void *:返回的是目标空间的起始地址
使用说明
- 函数memcpy从source的位置开始向后复制num个字节的数据到destination指向的内存位置。
- 这个函数在遇到 '\0' 的时候并不会停下来。
- 如果source和destination指向的空间有任何的重叠,复制的结果都是未定义的。
- 因为交换的变量有可能是不同的类型,使用函数接收的要用void*
#include <stdio.h>
#include <string.h>
int main()
{
int arr1[] = { 1,2,3,4,5,6,7,8,9,10 };
int arr2[10] = { 0 };
memcpy(arr2, arr1, 5 * sizeof(int));
int i = 0;
for (i = 0; i < 10; i++)
{
printf(