Question: The following program generates an error. Why? const int NUM _ ELEMENTS = 5 ; vector userVals ( NUM _ ELEMENTS ) ; unsigned int

The following program generates an error. Why?
const int NUM_ELEMENTS =5;
vector userVals(NUM_ELEMENTS);
unsigned int i;
userVals.at(0)=1;
userVals.at(1)=7;
userVals.at(2)=4;
for (i =0; i <= NUM_ELEMENTS; ++i){
cout << userVals.at(i)<< endl;
}
Group of answer choices
Variable i is declared as an unsigned integer.
The vector userVals has 5 elements, but only 3 have values assigned.
The integer NUM_ELEMENTS is declared as a constant
The for loop tries to access an index that is out of the vector's valid range.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!