c
#include <stdlib.h> // 包含 malloc 和 free
#include <string.h> // 包含 memcpy 函数
int source_array[] = {10, 20, 30, 40, 50};
// 动态分配内存给目标数组
int *destination_array = (int*)malloc(array_size * sizeof(int));
// 检查内存分配是否成功
if (destination_array == NULL) {
perror("内存分配失败"); // 打印错误信息
return 1; // 返回错误码
}
// 使用 memcpy 复制
// 参数1: 目标地址 (destination_array)
// 参数2: 源地址 (source_array)
// 参数3: 复制的字节数 (数组元素个数 * 每个元素的大小)
memcpy(destination_array, source_array, array_size * sizeof(int));