WorksheetsVectors C++
Total questions: 10
Worksheet time: 6mins
Which of the following does NOT exemplify a valid vector declaration?
vector<int> vec;
vector<int> vec(3);
vector<int> vec = 0,1,2;
vector<int> vec = {0,1,2};
Can you redefine the type of variables that a vector holds after creating it?
Yes
No
Which of the following refers to the THIRD element of a vector called names?
names[0]
names[2]
names[3]
names[4]
For the following vector of ints, what value is obtained from v.size()?
4
5
6
0
What is the value of sum?
6
4
8
1
What will be the new elements of vec (in a comma-separated list) after the following operations are performed?
1,6,3,7
1,6,7
1,6,3
6,3,7
For a vector called vec containing 4 elements, which of the following causes an index out of bounds error?
v[-17]
v[4]
all of the above
none of the above
Is this a for loop or a for each loop?
for loop
for each loop
Is this a for loop or a for each loop?
for loop
for each loop
True or false: A vector has a FIXED size, meaning you are not allowed to add new elements to it or remove existing ones.
True
False
