Variables & Constants (Cambridge (CIE) O Level Computer Science)
Revision Note
![Robert Hampton](https://www.savemyexams.com/cdn-cgi/image/f=auto,width=3840/https://cdn.savemyexams.com/uploads/2024/01/robert-hampton-computer-science-expert-save-my-exams.jpg)
Author
Robert HamptonExpertise
Computer Science Content Creator
Variables & Constants
What is a variable?
A variable is an identifier that can change in the lifetime of a program
Identifiers should be:
In mixed case (Pascal case)
Only contain letters (A-Z, a-z)
Only contain digits (0-9)
Start with a capital letter and not a digit
A variable can be associated a datatype when it is declared
When a variable is declared, memory is allocated based on the data type indicated
Pseudocode |
---|
DECLARE <identifier> : <datatype> |
|
|
|
Python |
---|
|
|
|
What is a constant?
A constant is an identifier set once in the lifetime of a program
Constants are named in all uppercase characters
Constants aid the readability and maintainability
If a constant needs to be changed, it should only need to be altered in one place in the whole program
Pseudocode |
---|
CONSTANT <identifier> ← <value> |
|
|
|
Python |
---|
|
|
|
You've read 0 of your 0 free revision notes
Get unlimited access
to absolutely everything:
- Downloadable PDFs
- Unlimited Revision Notes
- Topic Questions
- Past Papers
- Model Answers
- Videos (Maths and Science)
Did this page help you?