Array::crbegin() and array::crend() in C++ STL?


Here we will see the crbegin() and crend() functions of array in C++ STL.

The array::crbegin() function is used to get reverse iterator. It returns constant reverse iterator pointing to the last element of the container. This function does not take any parameter.

The array::crend() function is reverse of crbegin(). This returns the iterator which is pointing the last element of the reversed iterator.

Let us see some code examples to get better idea.

Example

 Live Demo

#include<iostream>
#include<array>
using namespace std;
main() {
   array<int, 10> arr = {00, 11, 22, 33, 44, 55, 66, 77, 88, 99};
   cout << "The list in reverse order: ";
   for(auto it = arr.crbegin(); it != arr.crend(); it++){
      cout << *it << " ";
   }
}

Output

The list in reverse order: 99 88 77 66 55 44 33 22 11 0

Updated on: 30-Jul-2019

54 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements