In C++ vectors, we can access last element using size of vector using following ways.
1) Using size()
1) Using back() We can access and modify last value using back().
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- How to find the maximum element of a Vector using STL in C++?
- How to find the minimum and maximum element of a Vector using STL in C++?
- Program to find frequency of each element in a vector using map in C++
- How to erase an element from a vector using erase() and reverse_iterator?
- vector::push_back() and vector::pop_back() in C++ STL
- vector::front() and vector::back() in C++ STL
- vector::empty() and vector::size() in C++ STL
- vector::crend() & vector::crbegin() with example
- vector :: cbegin() and vector :: cend() in C++ STL
- How to flatten a Vector of Vectors or 2D Vector in C++
- Accessing array out of bounds in C/C++
- vector::begin() and vector::end() in C++ STL
- vector::at() and vector::swap() in C++ STL
- Namespace in C++ | Set 3 (Accessing, creating header, nesting and aliasing)
- Vector in C++ STL
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.