.crbegin()
Anonymous contributor
Published Jun 10, 2025
Contribute to Docs
In C++, the .crbegin()
method returns a const_reverse_iterator
referring to the last element of the given array, i.e., the first element in reverse order. Because the iterator is constant, it cannot be used to modify the underlying elements.
Syntax
container.crbegin()
Parameters:
.crbegin()
takes no parameters.
Return value:
Returns a const_reverse_iterator
referring to the last element of the given array.
Example
This example prints the elements of an array in reverse order using constant reverse iterators (.crbegin()
and .crend()
):
#include <array>#include <iostream>int main() {std::array<int, 5> nums = {10, 20, 30, 40, 50};// Print the array in reverse using .crbegin() and .crend()for (auto it = nums.crbegin(); it != nums.crend(); ++it) {std::cout << *it << ' ';}std::cout << '\n';}
Here is the output:
50 40 30 20 10
Codebyte Example
Run this codebyte example to understand how the .crbegin()
method works:
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.