A vector is basically a dynamic array in which means you do not need to define the size before compiling it is done automatically
Be careful how you say that. The resizing is only done under certain conditions, and only if you use the correct operators/functions. If you use the subscript operator (operator) improperly, you will still get segmentation faults.
In order for the vector to resize, you need to use vector::resize() or vector::push_back(). I think vector::reserve() can cause a resize as well, but the site you linked seems to be having issues at the moment.
it was just a simple way of explaining it which some times helps people get their heads round things
Which is fine. But your language was misleading. The "Dynamic" nature of the vector only comes in to play if you use it correctly. Your post makes it sound like you use it just like an array without regard for boundaries.
A better way to say it would probably be "A vector is basically an array that allows you to modify its capacity when necessary."
>>I think vector::reserve() can cause a resize
>>The member functions vector::reserve()... both can cause re-allocation as well
Just to let you know, your first statement is different from your second. reserve does not "resize" the vector as in vector::resize does, so just be weary of the lingo. And as for your second statement, you should point out that, vector::reserve does not affect its element when it tries to change its capacity.
For why to make use of vectors, the answer is very simple. They make programming easier to maintain and modify later. They Produce compact code.
They are part of STL of standard C++ Implementation.
You should read a good C++ book covering STL. I think that will help you much better, then being on any forum or searching the web.
I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...
Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...