max_size() vs capacity in vector help confusion | Sololearn: Learn to code for FREE!

0

max_size() vs capacity in vector help confusion

i think max_size() give max number of element any vector can store & it will be constant for any vector. and capacity max number of element that depend upon numbeer of input or push_back operation.IN below code if i replace 100 by max_size()->4611686018427387903 then why it can't able to store the value since it has max_size(),and what is the use of max_size() if it is wrong // comparing size, capacity and max_size #include <iostream> #include <vector> int main () { std::vector<int> myvector; // set some content in the vector: for (int i=0; i<100; i++) myvector.push_back(i); std::cout << "size: " << myvector.size() << "\n"; std::cout << "capacity: " << myvector.capacity() << "\n"; std::cout << "max_size: " << myvector.max_size() << "\n"; return 0; }

6/23/2018 4:09:31 PM

Bahubali

5 Answers

New Answer

+2

Sincerally i think that its can be useful only on limited and reatricted system. Else i dont see any useful use with it (this is my opinion but someone can find a more useful use)

+1

max_size say you the POTENTIAL maximum that your vector can POSSIBLY store (depends on some factors which vector implementation) BUT this dont mean that you can reach this limit.

+1

thank u for helping me

+1

👍👍👍

0

so is there any use of it?or on my system it cant store