A named place in a computer program where you can store and change a value.
Details
Variables are like labeled boxes: you can store something inside, check what’s there, and update it.
They make programs flexible by allowing handling values that change during execution.
Consider keeping track of a player’s score:
🤖 Pseudocode
score = 0 # store the initial value score = 10 # change the value "Current Score:" score # use the current value
A variable creates a space in memory called score to hold the player’s score.
This allows the game to update the score as it changes and display it to the player.
To use a variable, we need to declare it first.
Declaring a variable, consists of telling the program to reserve a piece of memory to store some data.
Check Related Actions for details on how to perform different actions with variables.
Related Concepts
- Has: Data Type
- Used in: Naming Variables
Related Actions
- Used in: Perform Arithmetic Operation
- Used in: Check Odd or Even
- Used in: Assign a Value to a Variable
- Used in: Declare a Variable
- Used in: Increment or Decrement a Variable
- Used in: Print a Variable