Data types
Explain the concept of data types.
Different ways to store data, defined by the set of values it can take and the set of operations which can be performed on it.
Define user-defined data types.
Data types made from existing data types, with a custom data structure.
Why might a programmer choose to use a user-defined data type over existing data types?
Absolute control of the operations which can be performed on the data, so data cannot be accidentally, unusably changedMore memory efficient
Define integer.
A whole number value
State 3 examples of integers.
-25, 0, 245
Define real/ float.
A number with a fractional part
State 2 examples of real/ floats.
-13.5, 0.2
Define Boolean.
A value which can only be TRUE or FALSE.
Define character.
A letter, special character or number, represented in ASCII or Unicode.
State 2 examples of characters.
"a", "4"
Define string.
A collection of character values.
Define record.
A ordered collection of fields, where each field may have a different data type.
Define array.
A finite, indexed set of related elements which all have the same data type.
Variables
Define variable/ constant declaration.
Giving a memory location an identifier or name.
Define assignment in programming.
Giving a memory location an with a value.
Describe the difference between variables and constants
Variables are memory locations whose contents can change during the execution of a program, while constants are memory locations whose contents cannot change during execution of a program
State 3 advantages to using constants over variables in a program
- No way that variable cannot accidentally be changed, as assignment can only occur once and its identifier is unique.
- Quicker to change the value of a constant, as declaration can only occur at one location.
- Makes code more readable, therefore quicker to debug.
Explain why it is important to use meaning variable identifiers in a program.
Easier to readQuicker to understandEnables those unfamiliar with your code test, debug, and contribute (accessibility).
Flow Control Structures
Define iteration in programming.
Repeating a set of instructions.
Define definite iteration.
Repeating a set of instructions a known number of times.
Define indefinite iteration.
Repeating a set of instructions an unknown number of times, until a Boolean condition is met.
Define sequence in programming.
The execution of statements in the order they appear (top to bottom).
Define selection in programming.
Using relation operations to form Boolean conditions to decide if a set of instructions will be executed or not (IF statements).
The Call Stack & Scope
State the purpose of exception handling.
Prevents the program from crashing due to an error and/or informs the user of a error in the program.
Explain how exception handling works with system level data structures.
As an error occurs in a program, a exception is thrown. This computer handles the exception by pausing execution, saving the current state of the program to volatile store on the system stack and execution set of instruction defined within the catch block.
State three errors which may occur during program execution.
- Opening files which may or may not exist.
- Calling missing subroutines, variables etc..
- Performing operation on data types which cannot occur (diving by 0, or index out of range).
State 5 advantages of using subroutines.
- Individual subroutines can be separately tested simultaneously, shortening development time.
- Many subroutines can be written independently at the same time, shortening development time.
- Subroutines reduces the repetition of code, less likely for typing errors.
- Subroutines are compact and understandable as separate units, easier to read.
- Subroutines are self contained, independent of global variables by way of parameters, so can be reused in other programs.
Compare functions and procedures.
Both functions and procedures are types of subroutine, only functions return a value, while procedures do not return a value.
Define local variables.
Variables which only exist while the subroutine is executing Which are only accessible within a subroutine.
Define global variables.
Variables which can exist throughout the entire execution of a programWhich are accessible from any part of a program.
Why must local variables be preferred to global variables
- Local variables only exist on the call stack, so memory is freed up after a subroutine call and the program is memory efficient.
- Local variables have reduced scope, so cannot be unknowing changed.
- Local variables makes code modular.
Define stack frame.
A stack data structure where return return addresses, parameters and local variables (in that order) are pushed, containing all the data needed for a single subroutine call to be executed.
Define call stack.
A system level stack data structure, containing many stack frames, used to control the order of subroutine execution and nesting.
State the three essentials characteristics for a recursive subroutine.
- The base case itself.
- The base case must be met after a finite number of subroutine calls.
- For all other input values other than the base case, the routine must call itself.
Define base case within a recursive subroutine.
A Boolean condition, which when met will cause the routine to not call itself and unwind.