为什么copy(a,a+4,&b[4]);是将数组复制到数组b的尾部? 里面的&b[4]应该怎么理解?

2025-03-06 22:11:03
推荐回答(1个)
回答1:

&b[4]  是对数组b第五个元素首地址取地址,可以理解为将第五个元素开始的后面作为一个数组,然后

copy(a,a+4,&b[4]);

是将a数组以a[0]起始,a[4]结束的这一段区域复制到b数组的b[4]开始的后续空间里面去。

copy 函数的定义为:

template//模板定义
      OutputIterator copy(
      InputIterator _First, //首地址
      InputIterator _Last, //结尾地址 
      OutputIterator _DestBeg    //输出空间首地址
   );

 

_First

 

An input iterator addressing the position of the first element in the source range.

 

_Last

 

An input iterator addressing the position that is one past the final element in the source range.

 

_DestBeg

 

An output iterator addressing the position of the first element in the destination range.