wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Vectors C++

Total questions: 10

Worksheet time: 6mins

Name
Class
Date
1.

Which of the following does NOT exemplify a valid vector declaration?

a)

vector<int> vec;

b)

vector<int> vec(3);

c)

vector<int> vec = 0,1,2;

d)

vector<int> vec = {0,1,2};

2.

Can you redefine the type of variables that a vector holds after creating it?

a)

Yes

b)

No

3.

Which of the following refers to the THIRD element of a vector called names?

a)

names[0]

b)

names[2]

c)

names[3]

d)

names[4]

4.

For the following vector of ints, what value is obtained from v.size()?

a)

4

b)

5

c)

6

d)

0

5.

What is the value of sum?

a)

6

b)

4

c)

8

d)

1

6.

What will be the new elements of vec (in a comma-separated list) after the following operations are performed?

a)

1,6,3,7

b)

1,6,7

c)

1,6,3

d)

6,3,7

7.

For a vector called vec containing 4 elements, which of the following causes an index out of bounds error?

a)

v[-17]

b)

v[4]

c)

all of the above

d)

none of the above

8.

Is this a for loop or a for each loop?

a)

for loop

b)

for each loop

9.

Is this a for loop or a for each loop?

a)

for loop

b)

for each loop

10.

True or false: A vector has a FIXED size, meaning you are not allowed to add new elements to it or remove existing ones.

a)

True

b)

False