0
Vectors
I looked up the max capacity of a vector in c++, people were saying it can hold as many values as you want, if this is the case. Whats the point of arrays? why vector<int> test = {...}; why not int array[10] = {...};
10 Antworten
+ 1
Hazer C++ Begginer vector is resizable easily and can be used when you are not sure about number of members to be added into container... array is well for fixed size of allocation
+ 4
Arrays are allocated on the stack or in a data section of the program, while vectors are allocated on the heap. Performance wise, it’s very cheap to allocate things on the stack or to use a data section, while it’s not so cheap to allocate things on the heap. That is one of the main reasons to prefer arrays over vector where you can. It should also be noted that std::array<int, 10> is a better alternative to raw arrays.
+ 1
Hazer C++ Begginer I am sorry but could not get your point... do your question ask necessity for vector?
+ 1
Thanks!
0
yeah
0
because if you can use an array then why use vector
0
so if i was to use a vector, what would i do to add variables to it after declaration? also, does the vector have a size limit?
0
vector<int> vecInput;//declaration
vecInput.push_back(2);//add elements
0
Hazer C++ Begginer , please go through this once... feel free to ask any questions if you have :
https://www.sololearn.com/learn/261/?ref=app
0
yes