Programming Elements Flashcards
Identifier
A unique name for something (e.g. variable, constant, procedure, etc.) within the program
Variable
An identifier associated with a specific memory location, used to store data. Its value can change while a program runs
Constant
A named value within a program with a fixed value that does not change while the program runs
What are the benefits of declaring a constant? (2)
- When its value changes, only the declaration has to be changed
- It makes your code easier to read, debug and maintain
Why aren’t variable names beginning with underscores encouraged?
A considerable number of names beginning with underscores are already reserved for use by the system
Data type
The type of data stored in a variable
What does the data type of a variable define? (3)
- The type of data stored in a variable
- How much memory is needed to store it
- The operations that can be performed on it
Integer
Data type for whole numbers
Real OR Float
Data type for fractional numbers
Character
Data type for a single character
String
Data type for text (over 1 character). Sometimes limited to a length of 255 characters
Boolean
A true or false value
How much memory is typically needed to store:
- An integer?
- A float?
- A single character?
- A boolean?
- 2 or 4 bytes
- 4 or 8 bytes
- 1 byte
- 1 byte, although 1 bit would suffice
Assignment
When a variable is given a value
Initialisation
Explicitly setting the starting values of variables