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

Ngọc Trâm

New member
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
 
Answer: 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.
 

Tìm kiếm

Back
Top