English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C++ Usage and examples of vector max_size()

C++ Vector (Container)

This function is used to return the maximum number of elements that the vector (vector) can accommodate.

Syntax

Vector (vector) 'v' and maximum size 'm'. Syntax is:

int m = v.max_size();

Parameters

It does not contain any parameters.

Return Value

It returns the maximum number of elements that the vector (vector) can contain.

Example1

Let's see a simple example.

#include<iostream>  
#include<vector>  
using namespace std;  
int main()  
{  
vector<int> v{1,2,3,4,5};  
std::cout << v.max_size() << std::endl;  
return 0;  
}

Output Result:

1073741823

C++ Vector (Container)