[8.1.4f] Relational & Arithmetic Operators
[8.1.4f] Relational & Arithmetic Operators
What this page covers
This page teaches how to understand and use three families of operators that you will meet throughout IGCSE Computer Science programming tasks: arithmetic, relational, and logical. You will see what each operator means, how precedence affects the order of evaluation, and how to combine them to form accurate conditions in selection and iteration. Examples use clear, exam-friendly notation and focus on the exact operator set in the specification.
Operator families at a glance
| Family | Operators (as required) | Purpose | Typical result type |
|---|---|---|---|
| Arithmetic | + − / * ^ MOD DIV | Calculate numeric results: addition, subtraction, division, multiplication, power, remainder, and integer quotient. | Number (INTEGER or REAL). DIV gives an INTEGER; MOD gives an INTEGER remainder. |
| Relational | = < <= > >= <> | Compare two values to decide a relationship such as equality or order. | BOOLEAN (TRUE or FALSE). |
| Logical | AND OR NOT | Combine or invert Boolean expressions. | BOOLEAN. |
Arithmetic operators in detail
+, −, *, /, and ^ do what you expect: add, subtract, multiply, divide, and raise to a power. Two special operators matter a lot for whole-number work: DIV and MOD. DIV performs integer division (it discards any fractional part), while MOD returns the remainder after division. For example, if we divide 23 by 5, then the integer quotient is 4 and the remainder is 3, so 23 DIV 5 is 4 and 23 MOD 5 is 3.
Arithmetic: precedence and grouping
Operator precedence is the rule that decides the order in which parts of an expression are evaluated. A standard precedence that you should assume is: ^ first, then * and / and DIV and MOD, then + and −. When two operators have the same precedence, evaluate from left to right. Use parentheses to make the intended order explicit and to avoid mistakes during exams.
Expression: 7 + 3 * 2 DIV 3
- Evaluate *, /, DIV, MOD left to right: 3 * 2 = 6; then 6 DIV 3 = 2.
- Now 7 + 2 = 9.
Result: 9
Expression: (7 + 3) * 2 DIV 3
- Parentheses first: (7 + 3) = 10.
- Then 10 * 2 = 20; 20 DIV 3 = 6 (integer division).
Result: 6
Expression: 2 * 3 ^ 2
- Power first: 3 ^ 2 = 9.
- Then multiply: 2 * 9 = 18.
Result: 18
DIV and MOD precision
Real division keeps fractions: 23 / 5 = 4.6. Integer division discards them: 23 DIV 5 = 4. The remainder: 23 MOD 5 = 3.
A school has 125 pupils for a trip and each coach seats 40.
- Full coaches needed: 125 DIV 40 = 3
- Pupils left over for a smaller minibus: 125 MOD 40 = 5
With negative numbers, different languages define MOD differently. At IGCSE level you will mainly use non-negative dividends and divisors. If you see negatives, read the question carefully for definitions.
Relational operators in detail
Relational operators compare two values and produce a Boolean result. For numbers: = means equality, < less than, <= less than or equal to, > greater than, >= greater than or equal to, and <> not equal to. For strings, comparisons are usually lexicographical (alphabetical by character codes), but exam questions will tell you exactly what to assume if it matters. Most of the time at this level you will compare numbers or check equality of strings.
Age check: Is a customer eligible for a student ticket if age is 16 or under?
Use <=: age <= 16 is TRUE for 16 and under, FALSE otherwise. Using just < would wrongly exclude exactly 16.
Inclusive range: Valid mark is 0 to 100 inclusive. Write two comparisons joined logically: mark >= 0 AND mark <= 100.
<> tests inequality. Sometimes it is cleaner to use ELSE in selection rather than writing every possible not-equal case. Prefer clarity.
Logical operators in detail
Logical operators combine or invert Boolean results from comparisons. AND is true only if both parts are true. OR is true if at least one part is true. NOT flips a truth value. You will most often use these to join relational tests when checking ranges or multiple conditions.
| A | B | A AND B |
|---|---|---|
| TRUE | TRUE | TRUE |
| TRUE | FALSE | FALSE |
| FALSE | TRUE | FALSE |
| FALSE | FALSE | FALSE |
| A | B | A OR B |
|---|---|---|
| TRUE | TRUE | TRUE |
| TRUE | FALSE | TRUE |
| FALSE | TRUE | TRUE |
| FALSE | FALSE | FALSE |
NOT inverts a condition. Two useful equivalences called De Morgan's laws help simplify or re-express logic:
- NOT (A AND B) is the same as (NOT A) OR (NOT B)
- NOT (A OR B) is the same as (NOT A) AND (NOT B)
These are handy when questions ask you to remove a NOT that covers a bracketed expression.
Combining operators in conditions
Most program logic uses a pattern like: calculate or read values, compare them with relational operators, then combine comparisons with logical operators, and finally choose what to do using selection (IF...THEN...ELSE) or repeat steps using iteration (WHILE, FOR). Always prioritise clarity and correctness. Use parentheses to group logical parts just like arithmetic parts.
Worked conditional examples
Rule: Accept a score only if it is between 0 and 100 inclusive and it is an integer multiple of 5.
Condition: (score >= 0 AND score <= 100) AND (score MOD 5 = 0)
Rule: A child ticket applies if age <= 12 or if the customer holds a family pass.
Condition: (age <= 12) OR (hasFamilyPass = TRUE)
Rule: Reject usernames that are empty or longer than 15 characters.
Condition: (length <= 0) OR (length > 15)
Deep Dive: Precedence Tips for Exams
When time is tight, parentheses are your best friend. Even if you recall the full precedence order, adding brackets prevents misreads and shows the examiner your intended logic. For compound logic, prefer explicit grouping like (A AND B) OR C rather than relying on memory of which logical operator binds tighter. Finally, write range checks with two comparisons joined by AND, not with clever but unclear arithmetic tricks.
Deep Dive: When to choose DIV and MOD
Use DIV when you want a whole-number count of full groups (rows of seats, packs, pages). Use MOD when you care about the leftover part (spare seats, remaining items). Many scheduling, timetabling, and data-chunking tasks combine both: fullGroups ← n DIV size, remainder ← n MOD size.
Small reference snippet
// Pseudocode-style reminders
// Arithmetic: ^, *, /, DIV, MOD, +, -
hoursPerDay ← 24
days ← totalHours DIV hoursPerDay
leftoverHours ← totalHours MOD hoursPerDay
// Relational + Logical combined
IF (mark >= 0 AND mark <= 100) AND (mark MOD 5 = 0) THEN
OUTPUT "Valid step of 5"
ELSE
OUTPUT "Invalid"
ENDIF
Key Takeaways
- Arithmetic includes +, −, *, /, ^, DIV, MOD; mind the precedence and use parentheses for clarity.
- DIV returns an integer quotient, MOD returns the remainder; they are ideal for grouping and leftovers.
- Relational operators compare values and always yield a Boolean result used in conditions.
- Logical operators AND, OR, NOT combine or invert Booleans; group with parentheses to control evaluation.
- Write range checks explicitly with two comparisons joined by AND to avoid off-by-one errors.
- Prefer clear, well-bracketed expressions to prevent precedence mistakes during exams.