C++ std::array crbegin() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
std::array

Definition

In C++, std::array::crbegin() returns a read-only reverse iterator. It starts on the last element and moves toward the first one when you use ++.

The letters mean c for const and r for reverse. Use it with crend() when you want to read an array backwards. 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 crbegin with empty brackets. It takes no arguments.

C++
auto it = nums.crbegin();
int last = *it;
CallWhat it does
nums.crbegin()Returns a read-only reverse iterator that points to the last element.
*nums.crbegin()Reads the last element. It gives the same value as back().

With a reverse iterator, ++it moves toward the front of the array.

Library declarations
C++
const_reverse_iterator crbegin() const noexcept;

Parameters

ParameterDescription
Nonecrbegin() takes no parameters. Call it with empty brackets.

Return Value

Return ValueDescription
Const reverse iteratorA const_reverse_iterator that points to the last element. For std::array<T, 0> it equals crend().

C++ Examples

Example 1 — Print in Reverse

Read the array from last to first.

C++
#include <array>
#include <iostream>

int main() {
    std::array<int, 3> nums = {10, 20, 30};

    for (auto it = nums.crbegin(); it != nums.crend(); ++it) {
        std::cout << *it << ' ';
    }
    std::cout << '\n';
    return 0;
}

How It Works

  1. crbegin() starts on the last element, 30.
  2. Each ++it steps one place toward the front.
  3. The loop ends at crend(), after 10 has been printed.

Example 2 — Reverse Inside a Function

A function with a const array parameter can still walk backwards.

C++
#include <array>
#include <iostream>

void printBackwards(const std::array<char, 4>& letters) {
    for (auto it = letters.crbegin(); it != letters.crend(); ++it) {
        std::cout << *it;
    }
    std::cout << '\n';
}

int main() {
    std::array<char, 4> word = {'C', 'O', 'D', 'E'};
    printBackwards(word);
    return 0;
}

How It Works

  1. The parameter is const, so only read-only iterators are possible.
  2. The loop begins with E, the last letter, and ends with C.
  3. The letters are printed with no spaces, so CODE becomes EDOC.

Example 3 — Check a Palindrome

Compare the array from the front with the same array from the back.

C++
#include <algorithm>
#include <array>
#include <iostream>

int main() {
    std::array<int, 5> nums = {1, 2, 3, 2, 1};

    bool same = std::equal(nums.cbegin(), nums.cend(), nums.crbegin());

    std::cout << "Palindrome: " << (same ? "yes" : "no") << '\n';
    return 0;
}

How It Works

  1. std::equal walks two ranges at the same time and compares each pair.
  2. The first range goes forward from cbegin(), and the second goes backward from crbegin().
  3. Every pair matches (1-1, 2-2, 3-3), so the answer is yes.

Frequently Asked Questions

It returns a const reverse iterator that points to the last element of the array. Moving it with ++ goes toward the first element.
On a non-const array, rbegin() lets you change elements and crbegin() is read-only. On a const array both are read-only.
Yes. Both give the last element. back() is shorter when you only need that one value.
No. Use ++ in a reverse loop. The reverse iterator already handles the direction.
It lets you read an array backwards in a simple loop or algorithm, with the safety of a read-only iterator.

Next: crend()

Get a read-only reverse iterator past the first element with std::array.

crend() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful