Data Types Examples in CS Thinking

Start with the recap, study the fully worked examples, then use the practice problems to check your understanding of Data Types.

This page combines explanation, solved examples, and follow-up practice so you can move from recognition to confident problem-solving in CS Thinking.

Concept Recap

Categories that classify data values and determine which operations can validly be performed on them.

Different kinds of data (numbers, text, true/false) work differently.

Read the full concept explanation β†’

How to Use These Examples

  • Read the first worked example with the solution open so the structure is clear.
  • Try the practice problems before revealing each solution.
  • Use the related concepts and background knowledge badges if you feel stuck.

What to Focus On

Core idea: Operations depend on type: you can add numbers, concatenate strings.

Common stuck point: '5' (text) and 5 (number) are differentβ€”some languages convert automatically, some don't.

Worked Examples

Example 1

easy
Classify each value into its data type: (a) 42, (b) 'Hello', (c) 3.14, (d) TRUE.

Solution

  1. 1
    Step 1: 42 is a whole number with no decimal point β€” this is an integer.
  2. 2
    Step 2: 'Hello' is text enclosed in quotes β€” this is a string.
  3. 3
    Step 3: 3.14 has a decimal part β€” this is a float (real number). TRUE is a logical value β€” this is a boolean.

Answer

(a) Integer, (b) String, (c) Float/Real, (d) Boolean.
Data types define what kind of value a variable holds and what operations can be performed on it. The four fundamental types are integer, float, string, and boolean.

Example 2

medium
A program reads user input as a string '25'. What happens if you try to calculate '25' + 10 without type conversion? What should you do instead?

Practice Problems

Try these problems on your own first, then open the solution to compare your method.

Example 1

medium
For each scenario, choose the most appropriate data type: (a) a student's name, (b) number of students in a class, (c) whether a student passed, (d) a student's average grade (e.g., 87.5).

Example 2

hard
A program stores prices as integers in pence (e.g., 499 for Β£4.99) rather than as floats. Explain two advantages of this approach.

Background Knowledge

These ideas may be useful before you work through the harder examples.

variable