Skip to content
Related Articles

Related Articles

Improve Article

forward_list::max_size() in C++ STL

  • Last Updated : 27 Nov, 2018

std::forward_list::max_size() is an inbuilt function in CPP STL which returns the maximum number of elements can be held by forward_list. This value depends on system or library implementation.

Syntax:

forwardlist_name.max_size ()

Parameters: The function does not accept any parameters.

Return value:The function returns the maximum numbers that can be stored into the forward_list.

Below program demonstrates the above function:




// C++ program to illustrate the
// max_size() function
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
    // initialising the forward list
    forward_list<int> f;
  
    // print max number of values that 
    // can be held by forward_list
    cout << "Max_size of the list is " 
    << f.max_size() << endl;
  
    return 0;
}
Output:
Max_size of the list is 1152921504606846975
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.
My Personal Notes arrow_drop_up
Recommended Articles
Page :