**set::rbegin()**is a built-in function in C++ STL which returns a reverse iterator pointing to the last element in the container.**Syntax:**reverse_iterator set_name.rbegin()

**Parameters:**The function does not take any parameter.**Return value:**The function returns a reverse iterator pointing to the last element in the container.Program to demonstrate the set::rbegin() method:

**Program 1:**

`// CPP program to demonstrate the`

`// set::rbegin() function`

`#include <bits/stdc++.h>`

`using`

`namespace`

`std;`

`int`

`main()`

`{`

`int`

`arr[] = { 14, 12, 15, 11, 10 };`

`// initializes the set from an array`

`set<`

`int`

`> s(arr, arr + 5);`

`set<`

`int`

`>::reverse_iterator rit;`

`// prints all elements in reverse order`

`for`

`(rit = s.rbegin(); rit != s.rend(); rit++)`

`cout << *rit <<`

`" "`

`;`

`cout <<`

`"\nThe last element in set is "`

`<< *(s.rbegin());`

`return`

`0;`

`}`

*chevron_right**filter_none***Output:**15 14 12 11 10 The last element in set is 15

**set::rend()**in an inbuilt function in C++ STL which returns a reverse iterator pointing to the theoretical element right before the first element in the set container.**Syntax:**reverse_iterator set_name.rend()

**Parameter:**The function does not accepts any parameter.**Return value:**The function returns a reverse iterator pointing to the theoretical element right before the first element in the set container.Below programs illustrate the function:

**Program 1:**`// CPP program to demonstrate the`

`// set::rend() function`

`#include <bits/stdc++.h>`

`using`

`namespace`

`std;`

`int`

`main()`

`{`

`int`

`arr[] = { 4, 3, 5, 1, 2 };`

`// initializes the set from an array`

`set<`

`int`

`> s(arr, arr + 5);`

`set<`

`int`

`>::reverse_iterator rit;`

`// prints all elements in reverse order`

`for`

`(rit = s.rbegin(); rit != s.rend(); rit++)`

`cout << *rit <<`

`" "`

`;`

`return`

`0;`

`}`

*chevron_right**filter_none***Output:**5 4 3 2 1

## Recommended Posts:

- Handling the Divide by Zero Exception in C++
- Geometric Median
- Minimum operations of the given type required to make a complete graph
- Check if possible to shuffle a matrix with adjacent movements
- Generate a random permutation of 1 to N
- Minimum operations of given type to make all elements of a matrix equal
- Biggest Reuleaux Triangle inscribed within a square which is inscribed within an ellipse
- Remove any corner X rows and columns from a matrix
- Program to implement Linear Extrapolation
- Largest right circular cone that can be inscribed within a sphere which is inscribed within a cube
- Count of sub-strings that are divisible by K
- Biggest Reuleaux Triangle inscribed within a square which is inscribed within a hexagon
- Iterative Boundary traversal of Complete Binary tree
- Remove first X rows and columns from a matrix
- How to delete a range of values from the List using Iterator

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.