What are Vectors in C++(Object Oriented Programming) and how are they used ?
Vector is a part of the sequential container which holds an ordered collection of elements of one type. A vector holds all these elements in a contiguous area of memory. Random access of elements is efficient however insertion of elements at any other position other than the end of the vector is inefficient since each element to the right of the element to be inserted has to be shifted one by one which leads to inefficiency. Similarly deletion of an element besides the last element is inefficient as well.
The vector is a part of the std namespace and one must include #include header in order to use a vector.
#include
using namespace std;
int main()
{
vector v1;
v1.push_back(1);
v1.push_back(2);
}
The function capacity () returns the total number of elements that the vector can hold and size () returns the number of elements that are currently stored in the vector

#include <vector>
#include <vector>