June 2025
Intermediate to advanced
1093 pages
33h 24m
English
Once you get used to iterators, you won't need to readjust for handling C-arrays. For all algorithms from the standard library that take iterators as parameters, you can also use raw pointers. Why? Because raw pointers are just a specific form of iterator. They are thus compatible.
The beginning of a C-array is a raw pointer that can be used like an iterator. This happens as follows with int[6] and thus behaves almost as if it were a vector<int>.
// https://godbolt.org/z/zsqKz76cj#include <iostream> // cout#include <iterator> // ostream_iterator#include <algorithm> // copy, ranges::copyint main () { int data[6] = { 1, 2, 3, 7, 9, 10 }; std::ostream_iterator<int> out_it (std::cout,", "); std::copy(data, data+6, out_it); ...
Read now
Unlock full access