wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

C++ Arrays

Total questions: 12

Worksheet time: 36mins

Name
Class
Date
1.

Unlike regular variables, __________ can hold multiple values.

a)

constants

b)

named constants

c)

arrays

d)

floats

2.
In an array, every element has the same
a)
data type
b)
subscript
c)
memory location
d)
all of the above
3.

Unlike regular variables, __________ can hold multiple values.

a)

constants

b)

named constants

c)

arrays

d)

floats

4.

What is the last legal subscript that can be used with the following array?

int values[5];

a)

0

b)

5

c)

6

d)

4

5.

Given the following declaration, where is the value 77 stored in the scores array?

int scores[] = {83, 62, 77, 97, 86}

a)

scores[0]

b)

scores[1]

c)

scores[2]

d)

scores[3]

6.

To pass an array as an argument to a function, pass the __________ of the array.

a)

contents

b)

size, expressed as an integer

c)

name

d)

value of the first element

7.

What will the following code display?

int numbers[5] = {99, 87, 66, 55, 101};

for (int i = 1; i < 4; i++)

cout << numbers[i] << " ";

a)

99 87 66 55 101

b)

87 66 55 101

c)

87 66 55

d)

Nothing. This code has an error.

8.

An array of string objects that will hold five names would be declared with which of the following statements?

a)

string names[5];

b)

string names(5);

c)

string names 5;

d)

String[5] = names;

9.

Given the following declaration, where is the value 15 stored in the nums array?

int nums[] = {83, 15, 57, 87, 80}

a)

nums[0]

b)

nums[1]

c)

nums[2]

d)

nums[3]

10.

An array of double objects that will hold ten lengths would be declared with which of the following statements?

a)

double length[5];

b)

double length(10);

c)

double length[10];

d)

double length(9);

11.

What will the following code display?

int numbers[5] = { 66, 55, 101, 99, 87};

for (int i = 2; i < 5; i++)

cout << numbers[i] << " ";

a)

87 101 99 87

b)

101 99 87

c)

66 101 87

d)

Nothing. This code has an error.

12.

What is the last legal subscript (top index) that can be used with the following array?

int nums[10];

a)

0

b)

11

c)

9

d)

10