Data types and records
| English | Chinese | Pinyin |
|---|---|---|
| data type | 数据类型 | shù jù lèi xíng |
| record | 记录 | jì lù |
| field | 字段 | zì duàn |
| dot notation | 点号表示法 | diǎn hào biǎo shì fǎ |
Choosing the right data type 数据类型
- Every variable has a data type — the kind of value it holds and the operations allowed.
- Picking well keeps programs correct and efficient.
- When several values describe one thing, a record 记录 groups them.
A real (floating-point) type should be used to store a measurement such as a temperature.
Whole counts use integers; measurements use reals.
The basic data types
INTEGER— a whole number (counts, indexes, IDs).REAL— a number with a fractional part (money, measurements).STRING— text in quotes;CHAR— a single character.BOOLEAN—TRUE/FALSE(flags);DATE— a calendar date.- Pick the smallest precise type — a
BOOLEANflag, not the strings "yes"/"no".

The six basic data types, each with an example value
Which data type best stores a yes/no flag like "in stock"?
A flag has two states, so BOOLEAN (TRUE/FALSE) is the precise choice — not the strings "yes"/"no".
Match each value to the best data type for it.
Pick the precise type: BOOLEAN for a flag, REAL for fractional values, INTEGER for whole counts, STRING for text.
Records
- A record holds several fields 字段 of different types under one name.
TYPE TStockItem
DECLARE ItemID : INTEGER
DECLARE Category : STRING
DECLARE ItemCost : REAL
ENDTYPE
DECLARE Item1 : TStockItem
Item1.Category ← "Fruit" // dot notation reaches a field
- Use a record when values always belong together (a customer, a stock item); use separate variables for unrelated values.
A record groups fields under one name
A record bundles related fields together. Each field is a named label you reach with dot notation — Item1.Category — not by a numeric index.
A record is used to:
A record bundles fields of (possibly) different types that describe one thing. An array holds many values of the same type.
To set the Category field of a record variable Item1, you write:
Dot notation record.field reaches a field of a record.
Integers vs reals
Pick the type to fit the data. Use an integer for whole counts and a real/float for measurements — storing money as a float can give rounding errors, so many systems use integer "pennies".
- A record structure groups fields of different types; pseudocode data types include ARRAY and FILE.
You've got it
- types:
INTEGER,REAL,STRING,CHAR,BOOLEAN,DATE— pick the smallest precise fit - a record groups several fields of different types under one name
- reach a field with dot notation 点号表示法 (
Item1.Category) - use a record when the values always describe one thing together