110 likes | 118 Views
A C vector is an array-like container, but unlike arrays, its size can change dynamically. In this video, we will learn Why we use vectors in C , What is a vector in C along with its syntax. After that, we will understand member functions of C vector with the help of some hands-on examples. <br><br>1. Why we use vectors in C <br>2.u200b What is a vector in C <br>3. Syntax<br>4. Member functions of C <br>5. Modifiers<br>6.u200b Iterators<br>7.u200b Capacity<br><br>Learn more: https://www.simplilearn.com/c-plus-plus-programming-for-beginners-article<br>
E N D
What’s in it for you? Why we use vectors in C++? What is vector in C++? Syntax Member function of vectors Modifiers Iterators Capacity
Why we use vectors in C++ ? Vectors are used in C++ because unlike arrays it’s size can be changed during runtime It has some extra inbuilt features like push_back() , size() , empty() etc
What is vector in C++ ? It is not necessary to mention the size of vector while declaring it A vector is array like container, just like array it uses contiguous memory locations. But unlike array it’s size can change dynamically
Syntax vector<int>v1 vector<string>v2 vector<float>v3 Here, v1 ,v2, v3 are variable names
Member functions of vectors Modifiers 2. Iterators 3. Capacity
Modifiers It adds element at the end • push_back() • clear() It deletes the last element • erase() Inserts new elements before specified position Removes the elements from the container from the specified range It swaps the content between vectors • pop_back() • swap() It assigns new value to the vector It is used to remove all elements assign() insert()
Iterators begin() It returns the iterator to the beginning end() It returns the iterator to the end
Capacity size() It returns number of elements in the vector resize() empty() It changes the size It tests whether the vector is empty max_size() It returns maximum size of vector capacity() Returns size of allocated storage capacity