5. Common Operations & Built-in Functions
Cambridge pseudocode I/O routines, arithmetic (DIV/MOD), relational operators, Boolean logic, and unified string & numeric built-in functions.
Standard input/output commands, arithmetic operators, relational and Boolean logic, and unified string & numeric built-in functions.
5.1 Input & Output
// runnable
// Input and output demo
DECLARE Answer, Score, Lives : INTEGER
Score <- 10
Lives <- 3
INPUT Answer
OUTPUT "Your answer: ", Answer
OUTPUT Score
OUTPUT "You have ", Lives, " lives left"
5.2 Arithmetic Operators
Operator | Description |
|---|---|
| Addition |
| Subtraction |
| Multiplication |
| Division (result is always REAL) |
| Integer division (quotient only) |
| Modulus (remainder after division) |
5.3 Relational Operators
Operator | Description |
|---|---|
| Greater than |
| Less than |
| Greater than or equal to |
| Less than or equal to |
| Equal to |
| Not equal to |
The result of relational operations is always of data type BOOLEAN.
5.4 Logic Operators
The logic operators are AND, OR, and NOT. Operands and results are always BOOLEAN. Use parentheses to make order of operations explicit.
5.5 String Functions & Operations
Function Signature | Description | Example | Syllabus |
|---|---|---|---|
| Returns string length |
| Both |
| Returns y chars from position x |
| 9618 |
| Returns rightmost x chars |
| 9618 |
| Returns leftmost x chars |
| 0478 |
| Extracts y chars from position x |
| 0478 |
| Returns lower-case equivalent |
| Both |
| Returns upper-case equivalent |
| Both |
| Joins two strings |
| Both |
5.6 Numeric Functions
Function Signature | Description | Example | Syllabus |
|---|---|---|---|
| Returns integer part of x |
| Both |
| Random real in range 0 to x (exclusive) |
| 9618 |
| Converts number to string |
| 0478 |
| Parses string to number |
| 0478 |
| Rounds to the given number of decimal places |
| 0478 |
| Random real between 0 and 1 |
| 0478 |