wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

C++ Array

Total questions: 28

Worksheet time: 1hrs 24mins

Name
Class
Date
1.

Unlike regular variables, __________ can hold multiple values.

a)

constants

b)

named constants

c)

arrays

d)

floats

2.

To access an array element, use the array name and the element's ___________.

a)

data type

b)

subscript

c)

value

d)

name

3.

The name of an array stores the __________ of the first array element.

a)

value

b)

memory address

c)

element number

d)

data type

4.

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]

5.

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

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.

A two-dimensional array can be viewed as

a)

rows and columns

b)

arguments and parameters

c)

increments and decrements

d)

All of these

9.

An element of a two-dimensional array is referred to by

a)

the array name followed by the column number of the element

b)

the row subscript of the element followed by the column subscript of the element

c)

a comma followed by a semicolon

d)

the row subscript of the element followed by the array name

10.

An element of a two-dimensional array is referred to by

a)

the array name followed by the column number of the element

b)

the row subscript of the element followed by the column subscript of the element

c)

a comma followed by a semicolon

d)

the row subscript of the element followed by the array name

11.

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;

12.

A single value in an array is addressed by specifying…

a)

the name of the array followed by the index of the element.

b)

the name of the array ONLY.

c)

the index of the element followed by the name of the array.

d)

the index of the element in the array ONLY.

13.

Which of the following is a valid C++ array definition?

a)

int array[0];

b)

float $$payments[10];

c)

void numbers[5];

d)

int nums[10];

14.

The subscript (or index) of an array can be…

a)

an integer

b)

a floating point number

c)

a character

d)

a negative number

15.

What does the following code do?


for (int index = 0; index < 5; index++)

cin >> numbers[index];

a)

Place data into a four element array called numbers.

b)

Place data into a four element array called index.

c)

Place data into a five element array called numbers.

d)

Place data into a five element array called index.

16.

Which of the following array declarations is invalid?

a)

bool array1[10];

b)

double array2[20,0];

c)

char array3[30];

d)

double array4[7];

17.

In the statement a[3] = 5, which of the following is the index value?

a)

a

b)

3

c)

a[3]

d)

5

18.

If you leave out the size declarator in an array definition:

a)

You must provide an initialization list

b)

You are not required to initialize the array elements

c)

All array elements default to zero values

d)

Your array will contain no elements

19.

An array can store a group of values, but the values must be…

a)

the same data type

b)

each of a different data type

c)

constants

d)

integers

20.

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

21.

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

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

a)

scores[0]

b)

scores[1]

c)

scores[2]

d)

scores[3]

22.

What will the following code do?


const int SIZE = 5;

double x[SIZE];

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

{

x[i] = 0.0;

}

a)

Each element in the array is initialized to 0.0

b)

Each element in the array, except the first, is initialized to 0.0

c)

Each element in the array, except the first and the last, is initialized to 0.0

d)

An error will occur when the code runs

23.

To indicate that 100 locations should be reserved for the integer array p, the programmer should write the declaration int p[99];

a)

True

b)

False

24.

A function is designed to identify the position of the largest value in an array. The function is sent an integer array and the size of the array (25). Which of the following function declarations is correct?

a)

int largest_value( int a[25])

b)

largest_value (int a[], int 25)

c)

int largest_value (int a[], int size)

d)

int largest_value (int a[], size)

25.

To assign the contents of one array to another, you must use…

a)

the assignment operator with the array names

b)

the equality operator with the array names

c)

a loop to assign the elements of one array to the other

26.

To assign the contents of one array to another, you must use…

a)

the assignment operator with the array names

b)

the equality operator with the array names

c)

a loop to assign the elements of one array to the other

27.

C++ limits the number of array dimensions to two.

a)

True

b)

False

28.

When you pass an array into a function as an argument:

a)

the function can modify the contents of the array

b)

the function has a new copy of the array