Choosing between CHAR and STRING

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

Choosing between CHAR and STRING

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which data type suits a grade letter such as 'B'?
A CHAR
B STRING
2. Which data type suits a student's name?
A STRING
B CHAR
3. Which data type suits a phone number such as "07700900123"?
A STRING
B INTEGER
4. A program asks 'Do you want to continue? (Y/N)'. Which type stores the answer?
A STRING
B CHAR
5. Which statement is true?
A A CHAR can hold any length of text, including none
B A STRING can hold any length of text, including none

Match the Pairs

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

Left columnRight column
1DECLARE Grade : CHAR AGrade holds exactly one character, such as a grade letter like A, B or C
2DECLARE PhoneNumber : STRING BDECLARE Answer : CHAR
3A name can be any length, so it should be stored as a STRING CPhoneNumber holds text of any length; digits are stored as text because they are not used in calculations
4A yes or no answer of 'Y' or 'N' is always one character, so it is a CHAR DA surname can be many characters long, so it needs STRING, not CHAR. CHAR holds only one character.
5DECLARE Surname : CHAR EA grade letter is always exactly one character, so CHAR is the better choice. The CHAR literal would also use single quotes: 'A'.
6DECLARE Grade : STRING Grade ← "A" FDECLARE FirstName : STRING

Definitions

CHAR or STRING

Fill in the Blanks

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

1.
DECLARE Grade : ____ Grade ← 'B'
2.
DECLARE FirstName : ______ FirstName ← "Priya"
3.
DECLARE PhoneNumber : ______ PhoneNumber ← "07700900123"
4.
DECLARE Answer : ____ OUTPUT "Continue? (Y/N)" INPUT Answer
5.
DECLARE Comment : ______ Comment ← ""

Spot the Error

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

Question 1
A DECLARE Phone : INTEGER
B INPUT Phone
C OUTPUT Phone
Question 2
A DECLARE Grade : CHAR
B Grade ← 'B'
C DECLARE Name : STRING
D Name ← 'Sam'
Question 3
A DECLARE Answer : CHAR
B Answer ← "Yes"
C OUTPUT Answer
Question 4
A DECLARE Surname : STRING
B Surname ← ""
C Initial ← ''
Question 5
A DECLARE FirstName : CHAR
B INPUT FirstName
C OUTPUT FirstName

Answer Key

Choosing between CHAR and STRING
Section A: Quick Questions
Q1
A — CHAR
Q2
A — STRING
Q3
A — STRING
Q4
B — CHAR
Q5
B — A STRING can hold any length of text, including none
Section B: Match the Pairs
Q1
DECLARE Grade : CHAR → Grade holds exactly one character, such as a grade letter like A, B or C
Q2
DECLARE PhoneNumber : STRING → PhoneNumber holds text of any length; digits are stored as text because they are not used in calculations
Q3
A name can be any length, so it should be stored as a STRING → DECLARE FirstName : STRING
Q4
A yes or no answer of 'Y' or 'N' is always one character, so it is a CHAR → DECLARE Answer : CHAR
Q5
DECLARE Surname : CHAR → A surname can be many characters long, so it needs STRING, not CHAR. CHAR holds only one character.
Q6
DECLARE Grade : STRING Grade ← "A" → A grade letter is always exactly one character, so CHAR is the better choice. The CHAR literal would also use single quotes: 'A'.
Section C: Definitions
Q1
CHAR or STRING — Use CHAR for a value that is always exactly one character, like a grade letter or Y/N. Use STRING for text of any length, including none, like a name or phone number.
Section D: Fill in the Blanks
Q1
DECLARE Grade : CHAR Grade ← 'B'
Q2
DECLARE FirstName : STRING FirstName ← "Priya"
Q3
DECLARE PhoneNumber : STRING PhoneNumber ← "07700900123"
Q4
DECLARE Answer : CHAR OUTPUT "Continue? (Y/N)" INPUT Answer
Q5
DECLARE Comment : STRING Comment ← ""
Section E: Spot the Error
Q1
A — A phone number is not used in calculations and can start with 0, so it must be STRING. INTEGER would drop the leading zero. It should be DECLARE Phone : STRING.
Q2
D — Single quotes make a CHAR literal, which holds exactly one character. A name is a STRING and needs double quotes: Name ← "Sam".
Q3
B — A CHAR holds exactly one character, and "Yes" is a three-character STRING. For a Y/N answer use the single character 'Y'.
Q4
C — A CHAR must be exactly one character, so it cannot be empty. Only a STRING can be empty. It should be Initial ← 'K' with one character between the quotes.
Q5
A — A name can be any length, so it needs STRING. A CHAR can only hold one character. It should be DECLARE FirstName : STRING.