ZIMSEC O Level · Computer Science · Form 3, Form 4
Variables, constants and data types
- A variable is a named memory location whose value can change; a constant stays the same.
- Data types: integer (whole numbers), real/float (decimals), string (text), Boolean (TRUE/FALSE), character.
Operators
Arithmetic (+, −, *, /, MOD for remainder, DIV for whole-number division); comparison (=, <>, <, >, <=, >=); logical (AND, OR, NOT).
Arrays
An array stores many values of the same type under one name, accessed by an index, e.g. Marks[1] to Marks[30].
Procedures and functions
Subprograms that perform a task. A function returns a value. They avoid repeating code and make programs easier to test.
Languages and translators
- High-level languages (Python, Java, Visual Basic) are close to English; low-level languages (assembly, machine code) are close to the hardware.
- A compiler translates the whole program at once into machine code; an interpreter translates and runs one line at a time; an assembler translates assembly language.
Errors
Syntax errors (breaking language rules), logic errors (program runs but gives wrong results), runtime errors (e.g. dividing by zero).
Worked example: What is 17 MOD 5 and 17 DIV 5?
17 MOD 5 = 2 (the remainder); 17 DIV 5 = 3 (the whole number of times 5 fits)
Check yourself
- Which data type stores TRUE or FALSE?
- Give one difference between a compiler and an interpreter.
- What type of error is caused by writing “PRNT” instead of “PRINT”?
Show answers
- Boolean.
- A compiler translates the whole program at once; an interpreter translates one line at a time.
- A syntax error.
Questions about this topic (0)
No questions about this topic yet.
Sign in or create a free account to join in.