array::rbegin() and array::rend() in C++ STL
- array::rbegin() is a built-in function in C++ STL which returns a reverse iterator pointing to the last element in the container.
Syntax:
array_name.rbegin()
Parameters: The function does not accept any parameter.
Return value: The function returns a reverse iterator pointing to the last element in the container.
Program to demonstrate the array::rbegin() method:
Program 1:
// CPP program to illustrate// the array::rbegin() 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.rbegin()) << endl;// prints all the elementscout <<"The array elements in reverse order are:\n";for(autoit = arr.rbegin(); it != arr.rend(); 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::rend() is a built-in function in C++ STL which returns a reverse iterator pointing to the the theoretical element right before the first element in the array container.
Syntax:
array_name.rend()
Parameters: The function does not take any parameter.
Return value: The function returns a reverse iterator pointing to the theoretical element right before the first element in the array container.
Program to demonstrate the array::rend() method:
Program 1:
// CPP program to illustrate// the array::rend() 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.rbegin(); it != arr.rend(); it++)cout << *it <<" ";return0;}chevron_rightfilter_noneOutput:The array elements in reverse order are: 7 4 2 5 1
Recommended Posts:
- Find the Deepest Node in a Binary Tree Using Queue STL - SET 2
- C++ program to compare two Strings using Operator Overloading
- not1 and not2 function templates in C++ STL with Examples
- Go vs C++
- Trie Data Structure using smart pointer and OOP in C++
- Modular Exponentiation of Complex Numbers
- std::hash class in C++ STL
- History of C++
- What are Forward declarations in C++
- __builtin_inf() functions of GCC compiler
- Structures in C++
- Variables in C++
- Implementing Forward Iterator in BST
- Count substrings that contain all vowels | SET 2
- Machine Learning 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.



