C++ .crbegin()

Anonymous contributor's avatar
Anonymous contributor
Published Jun 10, 2025

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.

  • Learn C++ — a versatile programming language that’s important for developing software, games, databases, and more.
    • Beginner Friendly.
      11 hours

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:

Code
Output

All contributors

Learn C++ on Codecademy

  • Learn C++ — a versatile programming language that’s important for developing software, games, databases, and more.
    • Beginner Friendly.
      11 hours