Which of the following(s) can be used to access the last element of a vector v?

a) v.end()
b) v.cend()
c) both v.end() and v.cend()
d) vectors do not have a function to access the last element

1 thought on “Which of the following(s) can be used to access the last element of a vector v?”

  1. d
    Explanation: There are no function to access the last element of the vector. The end() and cend() returns the iterator to an element which is kept at the last of the vector to keep the knowledge about the end of a vector. In order to access the last element, you can first find the size and then can use v[size-1] or v.at(size – 1) to access the last element.

Leave a Comment