multimap rend in C++ STL
multimap::rend() is a built-in function in C++ STL which returns a reverse iterator pointing to the theoretical element preceding to the first element of the multimap container.
Syntax
multimap_name.rend()
Parameters: The function does not take any parameter.
Return ValueThe function returns a reverse iterator pointing to the reverse end of the multimap container i.e a reverse iterator pointing to the position right before the first element of the multimap.
The iterator returned by multimap::rend() cannot be dereferenced.
The following 2 programs illustrates the function
// CPP program to illustrate// multimap::rend()#include <iostream>#include <map>using namespace std; int main(){ multimap<char, int> sample; // Insert pairs in the multimap sample.insert(make_pair('a', 10)); sample.insert(make_pair('b', 20)); sample.insert(make_pair('c', 30)); sample.insert(make_pair('c', 40)); // Show content for (auto it = sample.rbegin(); it != sample.rend(); it++) cout << it->first << " = " << it->second << endl;} |
Output
c = 40 c = 30 b = 20 a = 10
Program 2
// CPP program to illustrate// multimap::rend() #include <iostream>#include <map>using namespace std; int main(){ multimap<char, int> sample; // Insert pairs in the multimap sample.insert(make_pair('a', 10)); sample.insert(make_pair('b', 20)); sample.insert(make_pair('c', 30)); sample.insert(make_pair('c', 40)); // Get the iterator pointing to // the preceding position of 1st element of the multimap auto it = sample.rend(); // Get the iterator pointing to // the 1st element of the multimap it--; cout << it->first << " = " << it->second;} |
Output
a = 10
Want to learn from the best curated videos and practice problems, check out the C++ Foundation Course for Basic to Advanced C++ and C++ STL Course for foundation plus STL. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.


