In C++, std::array::crend() returns a read-only reverse iterator that marks the end of a backward walk. It points to the place just before the first element.
Use it as the stop mark when you loop from crbegin(). Include <array> to use it.
This is a member of std::array<T, N>, not of a plain C array and not of std::vector. A std::array has a fixed size N that is part of its type, and it lives on the stack like a normal variable.
Syntax
Call crend with empty brackets. It takes no arguments.
C++
for (auto it = nums.crbegin(); it != nums.crend(); ++it) {
// read *it
}
Call
What it does
nums.crend()
Returns the stop mark for a read-only backward loop.
std::distance(nums.crbegin(), nums.crend())
Counts how many steps a reverse walk takes.
Like cend(), this iterator is only a mark. It does not point to a real element.
Library declarations
C++
const_reverse_iterator crend() const noexcept;
Parameters
Parameter
Description
None
crend() takes no parameters. Call it with empty brackets.
Return Value
Return Value
Description
Const reverse iterator
A const_reverse_iterator that marks the end of the reverse range. For std::array<T, 0> it equals crbegin().
C++ Examples
Example 1 — Loop Until crend()
Count each step while you walk backwards.
C++
#include <array>
#include <iostream>
int main() {
std::array<int, 3> nums = {10, 20, 30};
int step = 1;
for (auto it = nums.crbegin(); it != nums.crend(); ++it, ++step) {
std::cout << "Step " << step << ": " << *it << '\n';
}
return 0;
}
Output
Step 1: 30
Step 2: 20
Step 3: 10
How It Works
The variable step starts at 1 and grows with the iterator.
The loop keeps running while it is not crend().
The last element is printed first, so step 1 shows 30.
Example 2 — Count Steps with std::distance
Find how many steps lie between the two reverse marks.