Declaring a 1D array: DECLARE name : ARRAY[l:u] OF type

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Declaring a 1D array: DECLARE name : ARRAY[l:u] OF type

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which line correctly declares a 1D array of 30 student names (indexes 1 to 30)?
A DECLARE StudentNames : ARRAY(1:30) OF STRING
B DECLARE StudentNames : ARRAY[1:30] OF STRING
2. In ARRAY[1:30], what separates the lower bound from the upper bound?
A A colon :
B A comma ,
3. After running DECLARE Scores : ARRAY[1:5] OF INTEGER, what values are stored in the array?
A None yet - the declaration only sets up the array
B Five zeros, one in each element
4. Which declaration puts the data type in the correct place?
A DECLARE Prices : REAL ARRAY[1:10] OF
B DECLARE Prices : ARRAY[1:10] OF REAL
5. For DECLARE StudentNames : ARRAY[1:30] OF STRING, what is the lower bound?
A 1
B 30

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1DECLARE Marks : ARRAY[1:25] OF INTEGER ADeclares a 1D array called Temps with indexes 0 to 6, so it has 7 elements, each holding a REAL number
2DECLARE Temps : ARRAY[0:6] OF REAL BRound brackets are used instead of square brackets. The bounds must be written as [1:30].
3The bounds go inside square brackets with the lower bound first, then a colon, then the upper bound CDeclares a 1D array called Marks with indexes 1 to 25, so it has 25 elements, each holding an INTEGER
4The declaration only sets up the array and its data type; it does not store any values, so a separate assignment is needed to fill an element DThe word OF is missing before the data type. It should be ARRAY[1:20] OF INTEGER.
5DECLARE Names : ARRAY(1:30) OF STRING EDECLARE Scores : ARRAY[1:10] OF INTEGER Scores[1] ← 15
6DECLARE Marks : ARRAY[1:20] INTEGER FDECLARE Names : ARRAY[1:30] OF STRING

Definitions

DECLARE StudentNames : ARRAY[1:30] OF STRING

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
DECLARE StudentNames : ARRAY[1:30] OF ______
2.
_______ Scores : ARRAY[1:10] OF INTEGER
3.
DECLARE Marks : ARRAY[1_20] OF INTEGER
4.
DECLARE Temperatures : ARRAY[0:6] __ REAL
5.
// one element for each month DECLARE Rainfall : ARRAY[1:__] OF REAL

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A DECLARE G : ARRAY[1:5] OF CHAR
B G[1] ← 'A'
C G[2] ← 'C'
D G[6] ← 'B'
Question 2
A // T = 7 daily temperatures
B DECLARE T : ARRAY[1,7] OF REAL
C T[1] ← 21.5
D T[2] ← 19.0
Question 3
A DECLARE L : ARRAY[1:3] OF CHAR
B L[1] ← 'x'
C L(2) ← 'y'
D L[3] ← 'z'
Question 4
A DECLARE P : ARRAY[1:9] REAL
B P[1] ← 1.5
C P[2] ← 4.0
Question 5
A // F = 4 fruit initials
B DECLARE F : ARRAY[1:4] OF CHAR
C F[0] ← 'A'
D F[2] ← 'P'

Answer Key

Declaring a 1D array: DECLARE name : ARRAY[l:u] OF type
Section A: Quick Questions
Q1
B — DECLARE StudentNames : ARRAY[1:30] OF STRING
Q2
A — A colon :
Q3
A — None yet - the declaration only sets up the array
Q4
B — DECLARE Prices : ARRAY[1:10] OF REAL
Q5
A — 1
Section B: Match the Pairs
Q1
DECLARE Marks : ARRAY[1:25] OF INTEGER → Declares a 1D array called Marks with indexes 1 to 25, so it has 25 elements, each holding an INTEGER
Q2
DECLARE Temps : ARRAY[0:6] OF REAL → Declares a 1D array called Temps with indexes 0 to 6, so it has 7 elements, each holding a REAL number
Q3
The bounds go inside square brackets with the lower bound first, then a colon, then the upper bound → DECLARE Names : ARRAY[1:30] OF STRING
Q4
The declaration only sets up the array and its data type; it does not store any values, so a separate assignment is needed to fill an element → DECLARE Scores : ARRAY[1:10] OF INTEGER Scores[1] ← 15
Q5
DECLARE Names : ARRAY(1:30) OF STRING → Round brackets are used instead of square brackets. The bounds must be written as [1:30].
Q6
DECLARE Marks : ARRAY[1:20] INTEGER → The word OF is missing before the data type. It should be ARRAY[1:20] OF INTEGER.
Section C: Definitions
Q1
DECLARE StudentNames : ARRAY[1:30] OF STRING — Declares a 1D array named StudentNames with indexes 1 to 30 (lower:upper), each element holding a STRING. It only sets up the array; no values are stored yet.
Section D: Fill in the Blanks
Q1
DECLARE StudentNames : ARRAY[1:30] OF STRING
Q2
DECLARE Scores : ARRAY[1:10] OF INTEGER
Q3
DECLARE Marks : ARRAY[1:20] OF INTEGER
Q4
DECLARE Temperatures : ARRAY[0:6] OF REAL
Q5
// one element for each month DECLARE Rainfall : ARRAY[1:12] OF REAL
Section E: Spot the Error
Q1
D — The array was declared with indexes 1 to 5, so index 6 is above the upper bound and is out of range. The line should be G[5] ← 'B'.
Q2
B — The lower and upper bounds must be separated by a colon, not a comma. It should be ARRAY[1:7].
Q3
C — Array indexes use square brackets, not round brackets. The line should be L[2] ← 'y'.
Q4
A — The word OF is missing between the bounds and the data type. It should be DECLARE P : ARRAY[1:9] OF REAL.
Q5
C — The lower bound is 1, so index 0 does not exist in this array. The first element is F[1], so the line should be F[1] ← 'A'.