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 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:
- Minimum cells to be flipped to get a 2*2 submatrix with equal elements
- Nested Loops in C++ with Examples
- _Find_first() function in C++ bitset with Examples
- _Find_next() function in C++ bitset with Examples
- Left-Right traversal of all the levels of N-ary tree
- Difference between Iterators and Pointers in C/C++ with Examples
- ostream::seekp(pos) method in C++ with Exmaples
- Default Methods in C++ with Examples
- C++ Tutorial
- Hello World Program : First program while learning Programming
- Difference between Argument and Parameter in C/C++ with Examples
- <cfloat> float.h in C/C++ with Examples
- C/C++ #include directive with Examples
- C/C++ if else statement with Examples
- C/C++ if statement with Examples
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.
Improved By : Akanksha_Rai


