vector max_size() function in C++ STL

The vector::max_size() is a built-in function in C++ STL which returns the maximum number of elements that can be held by the vector container.

Syntax:

vector_name.max_size()

Parameters: The function does not accept any parameters.



Return value: The function returns the maximum numbers that can fit into the vector container.

Program below illustrates the above function:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate the
// vector::max_size() function
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
    // initialize a vector
    vector<int> vec;
  
    // returns the max_size of vector
    cout << "max_size of vector 1 = " << vec.max_size() << endl;
  
    vector<int> vec1;
  
    // returns the max_size of vector
    cout << "max_size of vector 2 = " << vec1.max_size() << endl;
    return 0;
}

chevron_right


Output:

max_size of vector 1 = 4611686018427387903
max_size of vector 2 = 4611686018427387903


My Personal Notes arrow_drop_up

Contented with little yet wishing for more

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.




Article Tags :
Practice Tags :


1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.