2.2 - Programming Fundamentals Flashcards
What are the main constructs?
- Sequence
- Selection
- Iteration
What is a variable?
Data that can change in value as a program is being run
What are local variables?
Declared within a specific subroutine
—> Can be only used within that subroutine
What are global variables?
Can be used at any point within the whole program
What are some advantages of local variables?
- Saves memory
- Easier to debug local variables
- You can reuse subroutines with local variables
How do local variables save memory?
Only uses memory when that local variable is needed
—> Global variables use memory whether they are used or not
How are local variables easier to debug?
As they can only be changed within one subroutine.
What are some advantages of global variables?
- Makes maintenance easier
- Can be used anywhere in the whole program
- Can be used for constants
How do global variables make maintenance easier?
As they are only declared once
What does modular mean?
Split into subroutines with each subroutine having a dedicated purpose
What is a constant?
Data that does not change in value as the program is run
What are comparison operators used for?
Compare two data values
What is the function of arithmetic operators?
Used to mathematically manipulate values
What is modulus?
Reveals the remainder from the last whole number
e.g.
9 % 4 = 1 (4 goes into 9 twice (8) with a remainder of 1)
What is the symbol for modulus?
%
What is integer division?
Reveals the ‘whole number of times’ a number can be divided into another number