CIE IGCSE | 8.1.2 Integer, Real, Char, String and Boolean

Lesson objective

Explain the five basic data types, recognise their literal notation and choose appropriate types for variables in a given scenario.

Learn

8.1.2 | INTEGER, REAL, CHAR, STRING AND BOOLEAN

01 | NOT ALL DATA MEANS THE SAME THING

A school booking program needs a number of tickets, a ticket price, a student’s name, a seating-zone letter and a paid-or-unpaid status. These are all data, but they are not all the same kind of information.

You calculate with a quantity and a price. You display a name as text. You use a payment status to choose what happens next. A data type describes the kind of value an item is intended to hold, helping determine which operations make sense.

Cambridge names five basic types for this section: INTEGER, REAL, CHAR, STRING and BOOLEAN. The important skill is not just recalling the names. It is choosing a type from the meaning of the data and its intended use.

We will build a small booking example as each type is introduced. All notation is Cambridge pseudocode; particular programming languages may use different names and syntax.

02 | INTEGER: WHOLE-NUMBER VALUES

An INTEGER holds a whole number, with no fractional part. Examples include zero, twelve and minus three. Whole number does not mean positive: negative values can also be integers.

DECLARE TicketQuantity : INTEGER
TicketQuantity ← 3
DECLARE Temperature : INTEGER
Temperature ← -2

A ticket quantity normally counts complete tickets, so INTEGER is suitable. In a scenario recording temperatures only as whole degrees, INTEGER can also suit a negative reading.

The type alone does not enforce every rule. An integer can be negative, even though a ticket quantity may be required to be non-negative. That restriction needs a validation rule.

Choose INTEGER for an item count, loop counter or whole-number score when the scenario specifies no fractional values. Do not use it for a measurement that needs values such as twenty-one point five.

03 | REAL: NUMBERS THAT CAN HAVE A FRACTIONAL PART

A REAL is a number capable of containing a fractional part. Prices, calculated means and measurements can require this type.

DECLARE TicketPrice : REAL
DECLARE TotalCost : REAL
TicketPrice ← 4.50
TotalCost ← 3 * TicketPrice

TotalCost becomes thirteen point five. REAL is suitable because a price need not be a whole number. A REAL can also hold a whole-valued quantity such as four point zero; it does not have to have a non-zero fractional part.

Cambridge REAL literals are written with at least one digit on each side of the decimal point, such as 0.5, 4.0 and -2.5. Use 0.5 rather than .5 in these pseudocode examples.

A mean may require REAL even if every input is INTEGER. Scores one and two have mean one point five. Type choice must account for the result, not only the input values.

04 | CHAR: EXACTLY ONE CHARACTER

A CHAR holds a single character. That character can be a letter, digit, punctuation symbol or space. It is not limited to alphabetical letters.

DECLARE SeatZone : CHAR
SeatZone ← 'B'
DECLARE MenuChoice : CHAR
MenuChoice ← '2'

The seat zone uses one character, B. The menu choice is the character two, not automatically the numeric quantity two. It can be compared with another menu-choice character.

In Cambridge pseudocode, CHAR literals use single quotes: 'B', '2' or '@'. A space written between single quotes is one character. An empty pair of quotes is not a one-character value.

A two-letter code such as AB needs STRING rather than CHAR. Use CHAR only when the information is defined as one character.

05 | STRING: A SEQUENCE OF CHARACTERS

A STRING holds a sequence of zero or more characters. Names, messages and identifiers are common examples.

DECLARE StudentName : STRING
DECLARE TicketCode : STRING
StudentName ← "Maya"
TicketCode ← "0072"

In Cambridge pseudocode, STRING literals use double quotes. A string can contain letters, spaces, digits and punctuation; it does not have to be a word.

The empty string, "", contains zero characters. It may be a useful starting value, but it would fail a requirement that a name must be supplied.

A string can also contain just one character, such as "B". That is still a STRING literal in this notation, whereas 'B' is a CHAR literal. Length alone is not the entire distinction: the declared type and literal notation also matter.

06 | NUMERIC-LOOKING DATA CAN STILL BE TEXT

A ticket code of 0072 identifies a ticket. You do not add ticket codes or calculate their mean. The leading zeros form part of the code and should be retained.

Representing it as an ordinary integer gives the numeric value seventy-two, rather than preserving the original four-character text. A STRING stores "0072" as an identifier.

Choose from meaning and use, not appearance alone
DataSuitable typeReason
Number of tickets: 72INTEGERA whole-number quantity used in calculations
Ticket code: "0072"STRINGText identifier; leading zeros matter
Telephone numberSTRINGIdentifying/contact text, possibly with + or leading zeros
Measured distance: 72.5REALA quantity with a fractional part

Quoted numeric text such as "12" is not automatically the numeric value twelve. Arithmetic needs appropriate numeric values. In an implementation, conversion may be required, but receiving text does not itself guarantee that conversion is valid.

Do not assume that an item called a number must be INTEGER. A phone number and a number of students have different roles.

07 | BOOLEAN: A TWO-STATE VALUE

A BOOLEAN holds one of the logical values TRUE or FALSE. It is useful for a yes-or-no state: whether a booking is paid, whether an item was found or whether a game is over.

DECLARE PaymentComplete : BOOLEAN
PaymentComplete ← FALSE
PaymentComplete ← TRUE

The initial value says payment is not complete. A later assignment records that it is. The variable’s name should make the meaning of TRUE clear.

Cambridge Boolean literals are TRUE and FALSE without quotation marks. "TRUE" is a string of four characters, not the Boolean value TRUE.

A Boolean is not a third-state item that also holds unknown. If the task needs an extra state such as pending, the data design needs to account for that separately. For this section, remember exactly two logical values.

08 | CONDITIONS PRODUCE BOOLEAN RESULTS

A comparison such as Score >= 10 produces a Boolean result. It is true or false depending on the current score.

DECLARE Score : INTEGER
DECLARE TargetReached : BOOLEAN
Score ← 12
TargetReached ← Score >= 10

Score is twelve, so the comparison is true and TargetReached receives TRUE. If Score had been seven, the comparison would have produced FALSE.

Assigning the result does not create a live link. If Score later changes to seven without recalculating TargetReached, TargetReached still holds TRUE. A new assignment is needed to update the stored result.

An IF statement can use a Boolean value to choose a branch. A value of FALSE is a valid logical result; it does not automatically mean the program has an error.

09 | THE FIVE TYPES AT A GLANCE

Cambridge pseudocode types and literal notation
TypeWhat it representsLiteral examplesTypical use
INTEGERWhole number0, 12, -3Quantity or counter
REALNumber capable of a fractional part0.5, 4.0, -2.5Price, measurement or mean
CHAROne character'B', '2', '@'Single-character option
STRINGZero or more characters"Maya", "0072", ""Name, message or identifier
BOOLEANLogical valueTRUE, FALSEStatus or condition result

A literal is a value written directly into an instruction. A variable identifier names an item that currently holds a value. The literal notation helps make the intended type clear.

The type distinction is independent of variable versus constant. A numeric price can be a fixed constant, while a numeric total can be a changing variable. Text can also be either fixed or changing, according to its role.

10 | READ A COMPLETE BOOKING EXAMPLE

This example prepares a booking record from illustrative values. It demonstrates declarations and assignment, not a full booking or payment system.

DECLARE TicketQuantity : INTEGER
DECLARE TicketPrice : REAL
DECLARE TotalCost : REAL
DECLARE SeatZone : CHAR
DECLARE StudentName : STRING
DECLARE TicketCode : STRING
DECLARE PaymentComplete : BOOLEAN
TicketQuantity ← 3
TicketPrice ← 4.50
TotalCost ← TicketQuantity * TicketPrice
SeatZone ← 'B'
StudentName ← "Maya"
TicketCode ← "0072"
PaymentComplete ← FALSE
OUTPUT "Student: ", StudentName
OUTPUT "Ticket code: ", TicketCode
OUTPUT "Zone: ", SeatZone
OUTPUT "Total: ", TotalCost

TicketQuantity counts three tickets. TicketPrice and TotalCost allow fractional amounts. SeatZone is one character, StudentName and TicketCode are text sequences, and PaymentComplete records a two-state status.

TotalCost is thirteen point five. The ticket code remains 0072. PaymentComplete is FALSE, but this example does not yet branch on that state.

The exact formatting of prices and Boolean display is a separate output concern. Choosing a type establishes meaning and permitted values; it does not automatically apply currency formatting or validation.

11 | CHOOSE A TYPE AND JUSTIFY IT

A good justification connects the data requirement to the type. “It is a number” is often too vague.

Quantity: “TicketQuantity is INTEGER because tickets are counted in whole units.”

Mean: “AverageScore is REAL because division can produce a fractional result even when the original scores are whole numbers.”

Code: “TicketCode is STRING because it is an identifier and must preserve leading zeros, rather than being used as a numeric quantity.”

Status: “PaymentComplete is BOOLEAN because the required state has two outcomes, complete or not complete.”

The scenario decides. A measurement rounded to whole units might use INTEGER; a measurement requiring fractional precision needs REAL. State the relevant assumption when the wording is unclear.

12 | RECOGNISE MISMATCHED VALUES

A declared type should match the values assigned to it. Do not rely on unspecified automatic conversion.

Fix the type or the data according to the requirement
Intended declaration and valueIssueSuitable change
DECLARE Quantity : INTEGER; Quantity ← 3.5A fractional quantity does not fit INTEGERUse REAL only if fractional quantities are actually permitted
DECLARE Zone : CHAR; Zone ← 'AB'Two characters do not form a CHAR literalUse STRING and "AB" for a two-character code
DECLARE Name : STRING; Name ← "Maya"No mismatchKeep STRING
DECLARE Paid : BOOLEAN; Paid ← "TRUE"Quoted text is not a Boolean literalAssign TRUE if that is the intended logical value

Changing INTEGER to REAL simply to silence a mismatch can be wrong if the task only permits whole tickets. Check the requirement, then reject invalid input or choose the correct representation.

A type is not the same as validation. An INTEGER mark can still be outside a permitted range; a STRING name can still be empty when presence is required.

13 | TRACE VALUES AND TYPES TOGETHER

Follow this short fragment with suitable declarations: Quantity is INTEGER, Price and Total are REAL, Code is STRING and Ready is BOOLEAN.

Quantity ← 2
Price ← 3.50
Total ← Quantity * Price
Code ← "002"
Ready ← Total >= 7.0
Quantity ← 3
A later quantity assignment does not automatically recompute dependent values
ItemFinal valueWhy
Quantity3Last assignment changes it
Price3.50No later update
Total7.0Calculated from the earlier quantity of two
Code"002"Text retains its leading zeros
ReadyTRUEStored result of seven being at least seven

Quantity and Code both relate to the digit two earlier in the run, but their meanings differ. One is a quantity; the other is an identifier.

To refresh Total after Quantity changes, explicitly repeat Total ← Quantity * Price. To refresh Ready after Total changes, repeat its comparison assignment too.

14 | AVOID THE COMMON MIX-UPS

INTEGER means positive: it also includes zero and negative whole numbers.

REAL means a non-zero fractional part: it can hold a whole-valued number too.

CHAR means a letter: a single digit or punctuation symbol can also be a character.

STRING must contain several characters: it can contain one or zero.

Digits always mean numeric data: identifiers can be numeric-looking strings.

"FALSE" is Boolean: the quoted form is text; FALSE without quotes is the Boolean literal.

Correct type means valid input: range, presence and other rules still need separate checking.

When unsure, ask what the information means, what values it may contain and what operations the algorithm needs to perform.

15 | TRANSFER YOUR UNDERSTANDING

Try choosing types for a weather logger: a whole-number reading count, a fractional temperature, a one-character sensor label, a station identifier and an alarm-active flag. Explain each choice before checking a model answer.

The same five types recur across scenarios. Learning the meaning lets you adapt your choices rather than memorising that every name, code or measurement always uses one particular type.

The next lesson uses these named values with INPUT, OUTPUT and user prompts. Keep the distinction between the value’s type, how it is received and how it is displayed.

CHOOSE THE DATA TYPE FOR EACH REQUIREMENT

Terminology

Terminology

Data type

The kind of value an item is intended to hold.

INTEGER

A whole-number type, including negative values and zero.

REAL

A numeric type capable of containing a fractional part.

CHAR

A type holding one character.

STRING

A sequence of zero or more characters.

BOOLEAN

A logical type with the values TRUE and FALSE.

Literal

A value written directly into an instruction.

Numeric value

A value representing a quantity on which numeric operations can be performed.

Text identifier

A character sequence used to identify an item rather than represent a quantity.

Leading zero

A zero at the beginning of a written value or identifier.

Empty string

A string containing zero characters, written "".

Character

A single text symbol, such as a letter, digit, punctuation mark or space.

Boolean expression

An expression that produces TRUE or FALSE.

Comparison

An operation comparing values and producing a Boolean result.

Declaration

An instruction introducing a variable and specifying its type.

Type mismatch

A value or operation inconsistent with the required data type.

Conversion

Changing a value’s representation from one type to another through an appropriate operation.

Validation

Checking whether data meets specified rules; type alone does not check every rule.

Questions

Questions

CHECK YOUR UNDERSTANDING

Select all correct choices. Each exact set earns one point.

1. Which are INTEGER values?
2. Which requirements suit REAL?
3. Which are CHAR literals in Cambridge notation?
4. Which are STRING literals?
5. Which are BOOLEAN literals?
6. Why choose STRING for ticket code 0072?
7. A mean is calculated from integer scores one and two. Which statements are correct?
8. Which statements distinguish types from validation?

EXPLAIN AND COMPARE

Write your answers before revealing each sample.

1. Define each of the five basic data types.

2. Compare INTEGER and REAL with a suitable use for each.

3. Compare CHAR and STRING using Cambridge literal examples.

4. Explain why a telephone number is often stored as STRING rather than INTEGER.

5. Suggest types for Quantity, AverageScore, GradeLetter, StudentName and Found.

6. Explain why "FALSE" and FALSE differ.

7. Score is twelve and Reached receives Score >= 10. Score then changes to seven without another Reached assignment. State Reached and explain.

8. Explain why declaring Mark as INTEGER does not enforce the range zero to fifty.

DESIGN IT | A WEATHER RECORD

Choose types and write declarations for a whole-number ReadingCount, fractional Temperature, one-character SensorLabel, station code "0041" and two-state AlarmActive. Assign example values zero, minus two point five, T, the station code and FALSE. Explain why the station code is not treated as an arithmetic quantity.

Reveal one possible solution
DECLARE ReadingCount : INTEGER
DECLARE Temperature : REAL
DECLARE SensorLabel : CHAR
DECLARE StationCode : STRING
DECLARE AlarmActive : BOOLEAN
ReadingCount ← 0
Temperature ← -2.5
SensorLabel ← 'T'
StationCode ← "0041"
AlarmActive ← FALSE

ReadingCount counts whole readings; Temperature permits a fractional part; SensorLabel contains one character; StationCode identifies the station and retains leading zeros; AlarmActive has two logical states.

Extend: assign AlarmActive ← Temperature < 0.0. It becomes TRUE because minus two point five is below zero. If the temperature later changes, the stored flag changes only when an instruction updates it.

Flashcards

Flashcards

Click to flip. Select the ideas you need to revisit.

0 cards selected for revision.

    Selections are kept while this page is open.

    Workbook

    Workbook

    COMING SOON

    The workbook for 8.1.2 Integer, Real, Char, String and Boolean is coming soon. Complete the matching task and written questions in your exercise book.