Introduction to C++ Programming
Learn C++ in step-by-step lessons.
Vectors
An array has a fixed number of elements, all of the same type. When you declare an array such as int numb[5]; the compiler calculates the amount of memory required: 5 *sizeof(int), and exactly that amount of space is allocated.
A vector does not have a fixed size and can grow larger or smaller as needed. Items are added to the end, as the last element, using the push_back method.
Both arrays and vectors can be traversed using a for loop: