deque max_size() function in C++ STL

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

Syntax:

deque_name.max_size()

Parameters: The function does not accept any parameters.

Return Value: The function returns the maximum number of elements that a deque container can hold.

Below programs illustrate the above function:



Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// CPP program to demonstrate the
// deque::max_size() function
// when deque is non-empty
#include <bits/stdc++.h>
using namespace std;
int main()
{
    deque<int> dq;
  
    dq.push_back(1);
    dq.push_back(10);
    dq.push_back(100);
    dq.push_back(50);
    dq.push_back(40);
    dq.push_back(23);
    dq.push_back(6);
  
    cout << "The deque elements: ";
    for (auto it = dq.begin(); it != dq.end(); it++)
        cout << *it << " ";
  
    cout << "\nThe max-size of deque: " << dq.max_size();
  
    return 0;
}

chevron_right


Output:

The deque elements: 1 10 100 50 40 23 6 
The max-size of deque: 4611686018427387903

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// CPP program to demonstrate the
// deque::max_size() function
// when deque is empty
#include <bits/stdc++.h>
using namespace std;
int main()
{
    deque<int> dq;
  
    cout << "The max-size of deque: " << dq.max_size();
  
    return 0;
}

chevron_right


Output:

The max-size of deque: 4611686018427387903

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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 :


Be the First to upvote.


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