Declaring CHAR and STRING variables

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

Declaring CHAR and STRING variables

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which line declares a variable called Initial that holds a single character?
A DECLARE Initial : CHAR
B DECLARE CHAR : Initial
2. Which line declares FirstName so it can hold text such as "Maya"?
A DECLARE FirstName = STRING
B DECLARE FirstName : STRING
3. A variable called Grade will always hold exactly one letter, such as 'B'. Which type fits best?
A CHAR
B STRING
4. A variable called Town will hold names such as "Manchester". Which type should you declare?
A STRING
B CHAR
5. Which line is a valid declaration?
A Surname : STRING
B DECLARE Surname : STRING

Match the Pairs

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

Left columnRight column
1DECLARE Initial : CHAR ADECLARE Grade : CHAR DECLARE Surname : STRING
2DECLARE FirstName : STRING BTwo variables are declared on one line. Each variable needs its own DECLARE line with its own type, and a surname is text, so it should be STRING.
3Each variable needs its own DECLARE line with one type, so declare a CHAR variable and a STRING variable on separate lines CCreates a variable called Initial that can hold a single character, such as 'A'
4Declare a variable to hold a whole word or sentence, such as a town name DCreates a variable called FirstName that can hold text of any length, such as "Ava"
5DECLARE Initial, Surname : CHAR EDECLARE Town : STRING
6DECLARE FirstName STRING FThe colon is missing between the identifier and the data type.

Definitions

DECLARE Initial : CHAR

Fill in the Blanks

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

1.
_______ Initial : CHAR
2.
DECLARE Initial : ____
3.
DECLARE FirstName : ______
4.
DECLARE Initial : CHAR DECLARE FirstName : ______
5.
DECLARE Initial _ CHAR DECLARE FirstName : STRING

Spot the Error

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

Question 1
A DECLARE Initial : CHAR
B DECLARE FirstName : STRING
C FirstName ← 'Ava'
Question 2
A DECLARE Grade : CHAR
B Grade ← 'BC'
C OUTPUT Grade
Question 3
A DECLARE Initial : CHAR
B DECLARE City : STRING
C DECLARE Country STRING
Question 4
A DECLARE Letter : CHARACTER
B Letter ← 'Q'
C OUTPUT Letter
Question 5
A DECLARE Initial : CHAR
B DECLARE LastName : STRING
C LastName = "Khan"

Answer Key

Declaring CHAR and STRING variables
Section A: Quick Questions
Q1
A — DECLARE Initial : CHAR
Q2
B — DECLARE FirstName : STRING
Q3
A — CHAR
Q4
A — STRING
Q5
B — DECLARE Surname : STRING
Section B: Match the Pairs
Q1
DECLARE Initial : CHAR → Creates a variable called Initial that can hold a single character, such as 'A'
Q2
DECLARE FirstName : STRING → Creates a variable called FirstName that can hold text of any length, such as "Ava"
Q3
Each variable needs its own DECLARE line with one type, so declare a CHAR variable and a STRING variable on separate lines → DECLARE Grade : CHAR DECLARE Surname : STRING
Q4
Declare a variable to hold a whole word or sentence, such as a town name → DECLARE Town : STRING
Q5
DECLARE Initial, Surname : CHAR → Two variables are declared on one line. Each variable needs its own DECLARE line with its own type, and a surname is text, so it should be STRING.
Q6
DECLARE FirstName STRING → The colon is missing between the identifier and the data type.
Section C: Definitions
Q1
DECLARE Initial : CHAR — DECLARE creates a variable and sets its type. Here Initial can hold one CHAR (a single character). Use : STRING instead for text, e.g. DECLARE FirstName : STRING.
Section D: Fill in the Blanks
Q1
DECLARE Initial : CHAR
Q2
DECLARE Initial : CHAR
Q3
DECLARE FirstName : STRING
Q4
DECLARE Initial : CHAR DECLARE FirstName : STRING
Q5
DECLARE Initial : CHAR DECLARE FirstName : STRING
Section E: Spot the Error
Q1
C — A STRING literal is written in double quotes. Single quotes are for a CHAR. It should be FirstName ← "Ava".
Q2
B — Grade is a CHAR, so it can hold only one character. 'BC' has two characters. Use a single character such as 'B', or declare Grade as STRING.
Q3
C — A DECLARE line needs a colon between the variable name and its type. It should be DECLARE Country : STRING.
Q4
A — CHARACTER is not a Cambridge data type. The type for a single character is CHAR. It should be DECLARE Letter : CHAR.
Q5
C — A value is assigned to a variable with the ← operator. The = sign is used for comparison. It should be LastName ← "Khan".