A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/cpp/multiset-max_size-in-cpp-stl-with-examples/ below:

multiset max_size() in C++ STL with Examples

multiset max_size() in C++ STL with Examples

Last Updated : 11 Jul, 2025

The

multiset::max_size()

is a built-in function in C++ STL which returns the maximum number of elements a multiset container can hold.

Syntax:
multiset_name.max_size()
Parameters:

The function does not accept any parameters.

Return Value:

The function returns the maximum number of elements a multiset container can hold. Below programs illustrate the above function:

Program 1: CPP
// CPP program to demonstrate the
// multiset::max_size() function
// when multiset is non-empty
#include <bits/stdc++.h>
using namespace std;
int main()
{

    multiset<int> s;

    // Function to insert elements
    // in the multiset container
    s.insert(10);
    s.insert(13);
    s.insert(13);
    s.insert(25);
    s.insert(24);

    cout << "The multiset elements are: ";
    for (auto it = s.begin(); it != s.end(); it++)
        cout << *it << " ";

    cout << "\nThe max size of multiset: " << s.max_size();
    return 0;
}
Output:
The multiset elements are: 10 13 13 24 25 
The max size of multiset: 461168601842738790
Program 2: CPP
// CPP program to demonstrate the
// multiset::max_size() function
// when multiset is empty
#include <bits/stdc++.h>
using namespace std;
int main()
{

    multiset<int> s;

    cout << "\nThe max size of multiset: " << s.max_size();
    return 0;
}
Output:
The max size of multiset: 461168601842738790
All functions of multiset

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4