Which assigns the vector's last element with 99?

Given a vector `myvector(15);`, choose the correct option:

A. `myvector(0) = 99;`
B. `myvector(14) = 99;`
C. `myvector(15) = 99;`
D. `myvector(16) = 99;`

Answer :

To assign the value 99 to the last element of a vector with 15 elements in C++, use the syntax myvector[14] = 99; since vector indexing is zero-based.

The question refers to the C++ STL vector class and asks how to assign the value 99 to the last element of a vector that has been initialized with a size of 15. In C++, vector indexing is zero-based, meaning that the first element is at index 0, the second element is at index 1, and so on up to the last element, which is at index size - 1. Therefore, for a vector with 15 elements, the last element is at index 14.

To correctly assign the value 99 to the last element of the vector myvector, we use the following syntax: myvector[14] = 99;