wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Arrays & Strings using C

Total questions: 15

Worksheet time: 11mins

Name
Class
Date
1.

Given the code, what is in values[2][1] ?

a)

7.9

b)

9.2

c)

7.3

d)

0.5

2.

Given the code, what is the value of things.length ?

a)

4

b)

3

c)

12

d)

7

3.

Given the following:

double [][] stuff ;

Which of the following statements constructs an array with 5 rows of 7 columns each and assign its reference to stuff ?

a)

stuff = new stuff[5][7] ;

b)

stuff = new double[5][7] ;

c)

new stuff = double[5][7] ;

d)

stuff = double new[5][7] ;

4.

Given the code, which of the following fragments prints out every element of items?

a)
b)
c)
d)
5.

Each piece of data in an array is BEST described as a what?

a)

Integer and string

b)

Item

c)

Element

d)

Elephant

6.

Which BEST describes an array?

a)

A data structure - Stores a collection of values under one name

b)

A data collection - Stores a structure of values under one name

c)

A list - Stores a list of numbers

d)

A list - Stores a list of strings

7.

Why are arrays useful?

a)

It saves storage space storing under one name

b)

You can store integers and strings together

c)

You can store thing related on different topics

d)

You may have lots of related data that you don't want to store separately

8.

Which of the following statements correctly declares a two-dimensional integer array?

a)

int Matrix[ ] = new int[5,4];

b)

int Matrix[ ]; Matrix = new int[5,4];

c)

int Matrix[ ][ ] = new int[5][4];

d)

int Matrix[ ][ ] = int[5][4];

9.

How would you get the value "6" out of the following array?

a)

a [0][3]

b)

a [1][3]

c)

c) a[0][2]

d)

d) a[2][0]

e)

e) a[3][1]

10.

What would the statement a[1].length return?

a)

3

b)

4

c)

2

d)

1

11.
What value is at index 1 in this array?  String[] names = {"Mack", "Dennis", "Dee", "Charlie"};
a)
Mack
b)
Dennis
c)
Dee
d)
Charlie
12.
True or False:  An array can be store different types of data (like store both doubles and ints).
a)
True
b)
False
13.
A two-dimensional array is a ___________ that contains multiple fields of data that are interrelated to a single record.  It field is referenced by x and y coordinates, often referred to as rows and columns.
a)
list
b)
cube
c)
table
d)
none of the above
14.
An array declaration contains _______________________ after its array name.
a)
an assignment operator
b)
keyword new
c)
a data type and rectangle brackets with a numeric size inside it
d)
all of the above
15.

An array elements are always stored in ________ memory locations.

a)

sequential

b)

Random

c)

Sequential and Random

d)

None of the above