multimap size() function in C++ STL

The multimap::size() is a built-in function in C++ STL which returns the number of elements in the multimap container.



Parameters: The function does not accept any parameter.

Return Value: This function returns the number of elements a multimap container has.





// C++ function for illustration
// multimap::size() function
#include <bits/stdc++.h>
using namespace std;
int main()
    // initialize container
    multimap<int, int> mp;
    // insert elements in random order
    mp.insert({ 2, 30 });
    mp.insert({ 1, 40 });
    mp.insert({ 2, 60 });
    mp.insert({ 2, 20 });
    mp.insert({ 1, 50 });
    mp.insert({ 4, 50 });
    cout << "multimap mp has " << mp.size()
         << " number of elements";
    return 0;



multimap mp has 6 number of elements

Rated as one of the most sought after skills in the industry, own the basics of coding with our C++ STL Course and master the very concepts by intense problem-solving.

My Personal Notes arrow_drop_up

The function of education is to teach one to think intensively and to think critically

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to 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.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at to report any issue with the above content.