CHAR data type

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

CHAR data type

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which value is a valid CHAR literal?
A 'x'
B "x"
2. Which value can be stored in a CHAR variable?
A '@'
B '@@'
3. Which statement about '7' is correct?
A '7' is an INTEGER, because 7 is a number
B '7' is a CHAR, because it is a single character in quotes
4. Which declaration creates a variable that holds one letter?
A DECLARE Grade : CHAR
B DECLARE Grade : LETTER
5. Which assignment is correct for Initial, a CHAR variable?
A Initial ← 'Mia'
B Initial ← 'M'

Match the Pairs

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

Left columnRight column
1DECLARE Grade : CHAR ADigit ← '7'
2Symbol ← '@' BLetter ← 'x'
3A CHAR literal is exactly one character inside single quotes CDeclares a variable named Grade that can store exactly one character
4A digit in single quotes is a character, not a number, so it is a CHAR value DA CHAR holds exactly one character, but 'AB' has two. Use one character such as 'A' or change the type to STRING.
5Initial ← "B" EDouble quotes were used. A CHAR value must be written in single quotes: 'B'.
6Letter ← 'AB' FStores the symbol @ in a CHAR variable using single quotes

Definitions

CHAR

Fill in the Blanks

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

1.
DECLARE Initial : ____
2.
DECLARE Digit : CHAR Digit _ '7'
3.
_______ Symbol : CHAR Symbol ← '@'
4.
DECLARE Initial : CHAR Initial ← 'K' ______ Initial
5.
DECLARE Symbol _ CHAR Symbol ← '#'

Spot the Error

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

Question 1
A DECLARE grade : CHAR
B DECLARE name : STRING
C grade ← 'BC'
D OUTPUT grade
Question 2
A DECLARE symbol : CHAR
B symbol ← "@"
C OUTPUT symbol
Question 3
A DECLARE digit : INTEGER
B digit ← '7'
C OUTPUT digit
Question 4
A DECLARE letter : CHAR
B letter ← x
C OUTPUT letter
Question 5
A DECLARE code : CHAR
B code ← 7
C OUTPUT code

Answer Key

CHAR data type
Section A: Quick Questions
Q1
A — 'x'
Q2
A — '@'
Q3
B — '7' is a CHAR, because it is a single character in quotes
Q4
A — DECLARE Grade : CHAR
Q5
B — Initial ← 'M'
Section B: Match the Pairs
Q1
DECLARE Grade : CHAR → Declares a variable named Grade that can store exactly one character
Q2
Symbol ← '@' → Stores the symbol @ in a CHAR variable using single quotes
Q3
A CHAR literal is exactly one character inside single quotes → Letter ← 'x'
Q4
A digit in single quotes is a character, not a number, so it is a CHAR value → Digit ← '7'
Q5
Initial ← "B" → Double quotes were used. A CHAR value must be written in single quotes: 'B'.
Q6
Letter ← 'AB' → A CHAR holds exactly one character, but 'AB' has two. Use one character such as 'A' or change the type to STRING.
Section C: Definitions
Q1
CHAR — The data type for exactly one character (a letter, digit or symbol), written in single quotes, such as 'x', '7' or '@'. Even '7' is a character, not a number.
Section D: Fill in the Blanks
Q1
DECLARE Initial : CHAR
Q2
DECLARE Digit : CHAR Digit ← '7'
Q3
DECLARE Symbol : CHAR Symbol ← '@'
Q4
DECLARE Initial : CHAR Initial ← 'K' OUTPUT Initial
Q5
DECLARE Symbol : CHAR Symbol ← '#'
Section E: Spot the Error
Q1
C — A CHAR holds exactly one character. 'BC' is two characters, so it would need to be a STRING. It should be grade ← 'B'.
Q2
B — CHAR values are written in single quotes, not double quotes. It should be symbol ← '@'.
Q3
A — '7' is a character, not a number, so the variable must be declared as CHAR. It should be DECLARE digit : CHAR.
Q4
B — A CHAR literal needs single quotes. Without them, x looks like a variable name. It should be letter ← 'x'.
Q5
B — 7 without quotes is an INTEGER. A CHAR must hold a character, so the digit needs single quotes: code ← '7'.