The correct way to assign the last element of a vector of integers named userNum with the value 20 would be:
userNum.at(userNum.size() - 1) = 20;
Step-by-step explanation:
userNum.at(userNum.size() - 1) is used to access the last element of the vector userNum. userNum.size() returns the number of elements in the vector, and subtracting 1 gives the index of the last element since vector indices are zero-based.
= is the assignment operator used to assign the value 20 to the last element of the vector.
So, the correct statement would be userNum.at(userNum.size() - 1) = 20;.