数组的拷贝
编写一个程序,初始化一个 double 类型的数组,然后把该数组的内容拷贝至3个其他数组中(在 main()中声明这4个数组)。
- 使用带数组表示法的函数进行第 1 份拷贝。
- 使用带指 针表示法和指针递增的函数进行第 2 份拷贝。 把目标数组名、源数组名和待 拷贝的元素个数作为前两个函数的参数。
- 第 3 个函数以目标数组名、源数组名和指向源数组最后一个元素后面的元素的指针。
- 也就是说,给定以下声明,则函数调用如下所示:
double source[5] = {1.1, 2.2, 3.3, 4.4, 5.5}; double target1[5];
#include <iostream>
#include <Windows.h>
#include <string.h>
using namespace std;
//方式一, 使用数组传值
void copy_arr(double target1[], double source[], int len) {
for (int i = 0; i < len; i++) {
target1[i] = source[i]