How can you access the last element of a C++ STL vector named "myVector"? 

  • myVector.end() 
  • myVector.last() 
  • myVector.back() 
  • myVector[myVector.size()]
The member function back() provides direct access to the last element in a vector. On the other hand, myVector.end() returns an iterator pointing to the position after the last element, and myVector[myVector.size()] would result in undefined behavior since it tries to access out-of-bounds memory. There's no last() function in vector.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *