💻 Computer Science · Topic 24 of 97

Variables and Data Types

A variable is a named location in memory that stores a value, and data types such as integer, string and Boolean describe what kind of value it holds.

▶ Interact

Play with the controls to see the idea in action.

Loading animation…

📘 Learn

A variable is a named location in memory that stores a value, and data types such as integer, string and Boolean describe what kind of value it holds.

  • Integer holds whole numbers
  • String holds text
  • Boolean holds true or false

🧠 Quick quiz

Three questions. Score 2 or more to complete the topic.

What is Variables and Data Types?

Within Computer Science, which covers algorithms, programming, data, networks, hardware and safe, responsible use of technology, this topic explains Variables and Data Types. Computing topics explain how software, hardware and data work, with diagrams and models that show each step in order.

Check that you can explain Variables and Data Types in your own words and give one example from everyday life. If you can do that, you have understood the core idea.

Understanding Variables and Data Types helps you design, test and explain programs, websites and systems, from small projects to exam questions.

Variables and Data Types in detail

A variable is a named storage location in memory that holds a value that can change while a program runs, such as score = 0. Choosing meaningful names (playerScore, not x) makes code readable. A constant has a value that does not change.

Data types define what kind of data a variable holds: integer (whole numbers), float or real (decimals), string (text), Boolean (True or False) and character. The type decides what operations can be done, such as arithmetic on numbers and joining on strings. Converting between types (casting) is often needed, for example turning a string input into an integer.

How the interactive helps you understand Variables and Data Types

Click a card to flip it and reveal the answer, then move on to the next one.

Before you change anything, predict the result. Then change one value at a time and check whether your prediction was right. This is a quick way to build a correct mental model of Variables and Data Types.

Real-life uses and examples

Common mistakes to avoid

Frequently asked questions about Variables and Data Types

What is Variables and Data Types?

A variable is a named location in memory that stores a value, and data types such as integer, string and Boolean describe what kind of value it holds.

What are the most important points about Variables and Data Types?

The main points are: Integer holds whole numbers; String holds text; Boolean holds true or false.

Why is Variables and Data Types useful?

Understanding Variables and Data Types helps you design, test and explain programs, websites and systems, from small projects to exam questions.

How can I practise Variables and Data Types?

Open the interactive at the top of this page and change the controls one at a time. Predict the result before each change, then take the three-question quiz. A score of two or more marks the topic as complete on this device.

Which topics are related to Variables and Data Types?

Related topics in Computer Science include Iteration: Loops, Functions and Procedures, Validation and Verification.

← PreviousComputational ThinkingNext →Operators and Expressions

Keep exploring Computer Science