C++Primer课后习题记录
编写 一个 接受 3 个 参数 的 函数: 指向 数组 区间 中 第一个 元素 的 指针、 指向 数组 区间 最后 一个 元素 后面 的 指针 以及 一个 int 值, 并将 数组 中的 每个 元素 都 设置 为 该 int 值。
//定义
void testt(int * start, int * end, int n){
while(start < end){
*start = n;
start++;
}
}
//调用
int arr[10];
testt(arr, arr + 10, 100);
for(int i = 0; i < 10; i++){
cout << arr[i] << endl;
}
注意:对指针进行加1,其实就是加上其指向类型的大小。
Last updated
Was this helpful?