Explore

Variables and Constants Flashcards
OCR GCSE J277 Computer Science specification
Ready to master these flashcards?
Sign in to study with spaced repetition and track your progress.
Sign In to Track ProgressTerms in this set (10)
Variable
A named storage location in memory that can hold a value which may change during program execution.
Constant
A named storage location in memory that holds a value which cannot change during program execution.
Purpose of variables
To store data that can be used and modified during the execution of a program.
Purpose of constants
To store data that remains the same throughout the execution of a program, improving readability and reducing errors.
Declaring a variable
Creating a variable by specifying its name and optionally assigning it an initial value.
Declaring a constant
Creating a constant by specifying its name and assigning it a value that cannot be changed.
Example of a variable
score = 0 (a variable named 'score' is created and assigned the value 0).
Example of a constant
PI = 3.14 (a constant named 'PI' is created and assigned the value 3.14).
Advantages of using constants
Improves code readability, prevents accidental changes, and makes updates easier if the value needs to be changed in the future.
Difference between variables and constants
Variables can change their value during program execution, while constants cannot.

Want to Learn More?
Get personalised lessons, quizzes, and instant feedback from your AI tutor.
Start Learning