array::crbegin() and array::crend() in C++ STL
- array::crbegin() is a built-in function in C++ STL which returns a constant reverse iterator pointing to the last element in the container.
Syntax:
array_name.crbegin()
Parameters: The function does not accepts any parameter.
Return value: The function returns a reverse iterator pointing to the last element in the container.
Program to demonstrate the array::crbegin() method:
Program 1:
// CPP program to illustrate// the array::crbegin() function#include <bits/stdc++.h>usingnamespacestd;intmain(){// array initialisationarray<int, 5> arr = { 1, 5, 2, 4, 7 };// prints the last elementcout <<"The last element is "<< *(arr.crbegin()) << endl;// prints all the elementscout <<"The array elements in reverse order are:\n";for(autoit = arr.crbegin(); it != arr.crend(); it++)cout << *it <<" ";return0;}chevron_rightfilter_noneOutput:The last element is 7 The array elements in reverse order are: 7 4 2 5 1
- array::crend() is a built-in function in C++ STL which returns a constant reverse iterator pointing to the the theoretical element right before the first element in the array container.
Syntax:
array_name.crend()
Parameters: The function does not accepts any parameter.
Return value: The function returns a constant reverse iterator pointing to the theoretical element right before the first element in the array container.
Program to demonstrate the array::crend() method:
Program 1:
// CPP program to illustrate// the array::crend() function#include <bits/stdc++.h>usingnamespacestd;intmain(){array<int, 5> arr = { 1, 5, 2, 4, 7 };// prints all the elementscout <<"The array elements in reverse order are:\n";for(autoit = arr.crbegin(); it != arr.crend(); it++)cout << *it <<" ";return0;}chevron_rightfilter_noneOutput:The array elements in reverse order are: 7 4 2 5 1
Recommended Posts:
- Print the path between any two nodes of a tree | DFS
- Find the Deepest Node in a Binary Tree Using Queue STL - SET 2
- Check whether Quadrilateral is valid or not if angles are given
- Modular Exponentiation of Complex Numbers
- Find the longest string that can be made up of other strings from the array
- Count substrings that contain all vowels | SET 2
- Flatten Binary Tree in order of Zig Zag traversal
- Implementing Multidimensional Map in C++
- Find the number which when added to the given ratio a : b, the ratio changes to c : d
- Draw an Ellipse rotating over a Circle in C++ graphics
- Remove first adjacent pairs of similar characters until possible
- Number of triangles formed by joining vertices of n-sided polygon with one side common
- Implementing ANDNOT Gate using Adaline Network
- Area of a Regular Pentagram
- std::uniform_int_distribution class in C++
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



