2.2.2

Data Types

Choosing the right data type helps a program store values accurately and use memory sensibly. You need to recognise the common data types, choose suitable ones for a scenario, and understand casting when data needs to be changed temporarily from one type to another.

13 exam questions 6 flashcards

What you need to know

  • Recognise integer, real, Boolean, character, and string data types.
  • Choose the most suitable data type for a scenario.
  • Explain what casting is and when it is useful.

Core Types

The data types you need to know

A strong exam answer often includes both the name of the data type and the reason it fits the situation.

Data typeStoresExample
IntegerWhole numbers27
RealNumbers with decimals3.14
BooleanTrue or falseTrue
CharacterA single character'A'
StringA sequence of characters"Hello"

High-Value Exam Skill

Choosing the right type for a scenario

Think about what kind of value is being stored and what operations need to be done with it.

  • Use integer for counts and whole-number quantities.
  • Use real for measurements that may include decimals.
  • Use Boolean for yes or no decisions.
  • Use character for one symbol and string for text.

Conversions

Casting

Casting means converting a value from one data type to another.

This is useful when input arrives as text but needs to be used in a calculation, or when a number needs to be turned into text for output.

Common example

If a user enters age as text, the program may cast it to an integer before using it in a calculation.

Key takeaways

  • Different types of data need different data types.
  • Integers are whole numbers, while reals can include decimal values.
  • Booleans store true or false values.
  • Casting changes a value from one type to another temporarily or deliberately.

Glossary

Integer
A whole number data type.
Real
A data type that can store decimal values.
Boolean
A data type that stores True or False.
String
A sequence of characters.
Casting
Converting data from one type to another.

Test yourself

Common questions