VCE Applied Computing (Year 11) · Unit 1 — Data Analytics · 16m read
Data Types and Structures
Ever wondered why your phone stores a phone number differently than a price? Data types are the categories that computers use to organize information — things like numbers, text, and true/false values — and choosing the right one makes your code faster and more reliable. Understanding data types is essential for VCE Computing and any programming you'll do, because the wrong choice can cause bugs or waste memory.
Learning objective: Understand fundamental data types and structures used in computing and data management.
By the end of this lesson you can:
- I can explain the difference between primitive data types (integer, float, string, boolean) and their uses.
- I can describe common data structures (arrays, records, tables) and when to use each.
- I can identify appropriate data types for given real-world data scenarios.
Data structures are storage furniture. Arrays are bookshelves, records are filing cards, dictionaries are labelled drawers.
Data types and structures in computing
### Primitive data types
Integer (int): Whole numbers, positive or negative. No decimal point.
- Examples: 42, -7, 0, 1000000
- Use for: counts, IDs, quantities, ages.
- Operations: arithmetic (+, −, ×, ÷), comparison (<, >, =).
Float / Real (float): Numbers with decimal points.
- Examples: 3.14, -0.5, 100.0
- Use for: measurements, prices, percentages, scientific data.
- Note: floating-point arithmetic can introduce tiny rounding errors.
String (str): Text — sequences of characters.
- Examples: "Hello", "42" (not a number!), "student@school.edu"
- Use for: names, addresses, descriptions, any text data.
- Operations: concatenation ("Hello" + " World"), length, search, substring.
Boolean (bool): True or False only.
- Examples: True, False
- Use for: flags, conditions, yes/no values (enrolled: True, graduated: False).
- Operations: AND, OR, NOT.
Character (char): A single character.
- Examples: 'A', '7', '!'
### Choosing the right data type
| Real-world data | Data type | Reason |
|----------------|-----------|--------|
| Student age | Integer | Whole numbers; no decimal ages |
| Exam score (%) | Float | May include decimal places |
| Student name | String | Text data |
| Enrolled (yes/no) | Boolean | Two states only |
| Phone number | String | Not used for arithmetic; may start with 0 |
| Postcode | String | Leading zeros matter (e.g., 0800); not used for arithmetic |
### Data structures
Array / List: An ordered collection of items of the same type.
- Example: scores = [85, 92, 78, 95]
- Access by index: scores[0] = 85
- Use for: collections of similar items.
Record: A collection of related fields of different types describing one entity.
- Example: Student record = {name: "Sam", age: 16, enrolled: True}
- Use for: representing a single entity with multiple attributes.
Table (2D structure): Rows of records with consistent columns.
- Like a spreadsheet or database table.
- Each row = one record. Each column = one field.
- Use for: datasets with multiple records sharing the same structure.
### Type conversion and validation
Type conversion: Changing data from one type to another.
- String to integer: "42" → 42 (for calculation).
- Integer to string: 42 → "42" (for display or concatenation).
Data validation: Checking that input matches the expected type and format.
- Range check: age must be 0-120.
- Type check: score must be a number, not text.
- Format check: email must contain @ and a domain.
- Presence check: required fields must not be empty.
Key ideas at a glance
- Choose by access pattern: Index vs key.
- Arrays are zero-indexed: First = 0.
- Records group fields: Related data.
- Validate input: Existence, type, range.
Worked example (Medium)
For an online bookstore database, identify the appropriate data type for each field: BookTitle, Price, ISBN, InStock, PageCount, Rating.
- BookTitle. String — text data of variable length. "The Great Gatsby", "War and Peace".
- Price. Float — currency values require decimal places. $29.95, $9.99.
- ISBN. String — although it looks like a number, ISBNs contain hyphens (978-0-13-468599-1) and are never used for arithmetic. Leading zeros matter.
- InStock. Boolean — True/False. Either the book is available or it isn't.
- PageCount. Integer — whole number. Books have 200 pages, not 200.5.
- Rating. Float — ratings like 4.5 out of 5 require decimal precision.
Answer: Choosing the correct data type for each field ensures data integrity, appropriate operations, and efficient storage.
Worked example (Hard)
A student enters their phone number as an integer (412345678). Explain why this causes a problem and what data type should be used.
- The problem. Phone numbers starting with 0 (e.g., 0412345678) lose the leading zero when stored as an integer — 0412345678 becomes 412345678. The phone number is now invalid.
- Why it happens. Integers represent numerical values. The number 0412345678 and 412345678 are mathematically equal — integers don't preserve leading zeros. But for phone numbers, the leading zero is meaningful (it's part of the formatting).
- The solution. Store phone numbers as strings. Strings preserve every character exactly — including leading zeros, spaces, and formatting characters like hyphens.
- General principle. Just because data LOOKS like a number doesn't mean it IS a number. The test: would you ever do arithmetic on it? You wouldn't add two phone numbers or calculate the average postcode. If not, use a string.
Answer: Phone numbers, postcodes, and ID numbers should be stored as strings — not integers — because they are identifiers, not quantities. Leading zeros, formatting, and non-arithmetic nature require string storage.
Common mistakes
- Storing phone numbers or postcodes as integers This is a common error. Fix: These are identifiers, not quantities. Leading zeros are lost in integer storage. Always use strings for data that looks like numbers but isn't used for arithmetic.
- Confusing "42" (string) with 42 (integer) This is a common error. Fix: "42" is a string — a sequence of characters '4' and '2'. 42 is an integer — a numerical value. "42" + "8" = "428" (concatenation). 42 + 8 = 50 (addition). Type matters!
- Not validating data input This is a common error. Fix: User input is always untrusted. If you expect an integer and the user types "hello", your program may crash. Always validate input type, range, and format before processing.
Why computers use binary data types
At the lowest level, computers store everything as binary (0s and 1s). An integer is stored as a binary number. A float uses a special format (IEEE 754) that separates the number into sign, exponent, and mantissa — which is why floating-point arithmetic can have tiny rounding errors (0.1 + 0.2 = 0.30000000000000004 in many languages). A character is stored as a number using an encoding system (ASCII: A=65, B=66; Unicode: supports every writing system on Earth). Understanding that all data types are ultimately binary explains both the power and the limitations of digital data representation.
Practice questions
The most appropriate data type for storing an Australian postcode (e.g., 0800) is:
- Integer
- Float
- String
- Boolean
(1 marks)
Explain the difference between a primitive data type and a data structure, giving examples of each.
(3 marks)
Summary
- Primitive types: integer (whole numbers), float (decimals), string (text), boolean (True/False).
- Choose based on purpose: identifiers → string; quantities → integer/float; yes/no → boolean.
- Leading zeros test: phone numbers, postcodes, ISBNs → always string (never integer).
- Data structures: array (ordered collection), record (multiple fields), table (rows of records).
- Validation: range check, type check, format check, presence check. Never trust user input.