Here's an illustration of which is which
v: [ 1 | 2 | 3 | 4 | ... | 999 ]
front() back() end()
begin()
where front() and back() return a (const) reference to the first and last element respectively, and end() returns an iterator (sort of a pointer) to one beyond the last element of vector. begin() returns an iterator to the first element of a vector.
These are also explained at std::vector
front access the first element
back access the last element
end/cend returns an iterator to the end
begin/cbegin returns an iterator to the beginning
Subtracting one from size is because an index in C or C++ starts at zero, and not one as usually. This means, in order to access the first element of an array, or in this case of a vector, you say
v[0]
and not
v[1]
Equally for the last (nth) element, you wouldn't take size or n of an array (a vector), but rather one less, e.g.
v[size() - 1]
or
v[n - 1]