Back to Topics/Operators/Arithmetic, Relational & Logical Operators
Page 8.xOperators

Arithmetic, Relational & Logical Operators

Master the six arithmetic operators, six relational operators, and three logical operators (AND, OR, NOT) — plus the precedence rules that decide how CIE pseudocode evaluates complex expressions.

6
Sections
6
Knowledge Checks
12
Questions
Operators
Category

8.1 Arithmetic Operators

Arithmetic operators perform mathematical calculations on numeric values (INTEGER and REAL). CIE pseudocode supports six arithmetic operators — four are familiar from maths class, while MOD and DIV are specialised for integer work.

OperatorNameExampleResult
+Addition7 + 310
-Subtraction7 - 34
*Multiplication7 * 321
/Division (REAL)7 / 23.5
DIVInteger Division7 DIV 23
MODModulus (Remainder)7 MOD 21

Key Distinction: / vs DIV vs MOD

/ always returns a REAL (decimal) result, even when the numbers divide evenly.DIV returns the integer quotient (the whole-number part of the division, truncated towards zero).MOD returns the remainder after integer division. Together: (A DIV B) * B + (A MOD B) = A.

Example: Arithmetic in Action
DECLARE Total : INTEGER
DECLARE Count : INTEGER
DECLARE Average : REAL

Total <- 17
Count <- 5

Average <- Total / Count          // 3.4 (REAL division)
OUTPUT Total DIV Count            // 3    (integer quotient)
OUTPUT Total MOD Count            // 2    (remainder)
OUTPUT Average                    // 3.4

Notice how DIV truncates (drops the decimal) rather than rounding — 17 DIV 5 is 3, not 4, even though 17 ÷ 5 = 3.4 rounds to 3.

8.2 Relational Operators

Relational operators compare two values and always produce aBOOLEAN result — either TRUE or FALSE. They are the building blocks of every IF condition and every loop condition.

OperatorMeaningExampleResult
=Equal to5 = 5TRUE
<>Not equal to5 <> 6TRUE
<Less than3 < 7TRUE
>Greater than9 > 2TRUE
<=Less than or equal to5 <= 5TRUE
>=Greater than or equal to6 >= 8FALSE

Important: = is Comparison, not Assignment

In CIE pseudocode, the single equals sign = is the comparison operator (it asks "are these equal?"), while the arrow <- is the assignment operator (it stores a value). This is different from languages like Python or Java where = assigns and == compares.

Example: Relational Operators in Conditions
DECLARE Age : INTEGER
INPUT Age

IF Age >= 18 THEN
    OUTPUT "You can vote."
ENDIF

IF Age <> 0 THEN
    OUTPUT "Age is not zero."
ENDIF

IF Age = 18 THEN
    OUTPUT "Exactly eighteen!"
ENDIF

Each condition (Age >= 18, Age <> 0, Age = 18) evaluates to TRUE or FALSE, and the IF statement acts on that BOOLEAN result.

8.3 Logical Operators (AND, OR, NOT)

Logical operators combine or modify BOOLEAN values. They let you build complex conditions from simpler ones — for example, "age is at least 13 AND age is at most 19" describes a teenager. CIE pseudocode supports three logical operators.

AND

Returns TRUE only when both operands are TRUE. Acts like a strict gate — both conditions must pass.

OR

Returns TRUE when at least one operand is TRUE. Acts like a lenient gate — any one condition passing is enough.

NOT

A unary operator that inverts a single BOOLEAN value: NOT TRUE = FALSE, NOT FALSE = TRUE.

The truth tables below show every possible combination of inputs and the resulting output:

ABA AND B
TRUETRUETRUE
TRUEFALSEFALSE
FALSETRUEFALSE
FALSEFALSEFALSE
ABA OR B
TRUETRUETRUE
TRUEFALSETRUE
FALSETRUETRUE
FALSEFALSEFALSE
ANOT A
TRUEFALSE
FALSETRUE
Example: Combining Conditions
DECLARE Age : INTEGER
DECLARE HasTicket : BOOLEAN

INPUT Age
INPUT HasTicket

IF Age >= 18 AND HasTicket = TRUE THEN
    OUTPUT "Welcome to the show."
ENDIF

IF Age < 13 OR Age > 65 THEN
    OUTPUT "Discount applies."
ENDIF

IF NOT HasTicket THEN
    OUTPUT "Please buy a ticket first."
ENDIF

8.4 Operator Precedence

When an expression contains several operators, CIE pseudocode evaluates them in a fixed order called operator precedence. Operators with higher precedence are evaluated first. Understanding this order is essential — getting it wrong is one of the most common sources of logic errors in exams.

OrderOperator(s)Category
1 (highest)( )Parentheses — always evaluated first
2* / MOD DIVMultiplication, division, modulus
3+ -Addition, subtraction
4= <> < > <= >=Relational (comparison)
5NOTLogical NOT (unary)
6ANDLogical AND
7 (lowest)ORLogical OR

Memory Aid

Think of it as: Parentheses → Arithmetic → Relational → Logical ("PARL"). Within arithmetic: multiply/divide before add/subtract. Within logical: NOT, then AND, then OR.

Example: Precedence in Action
// Example 1: Arithmetic precedence
OUTPUT 2 + 3 * 4        // 14, NOT 20  (* first, then +)

// Example 2: Parentheses override precedence
OUTPUT (2 + 3) * 4      // 20  (parentheses force + first)

// Example 3: Relational + Logical
// Age >= 13 is evaluated first (relational),
// then AND, then OR (lowest)
IF Age >= 13 AND Age <= 19 OR Age = 65 THEN
    OUTPUT "Teenager or senior"
ENDIF

// Example 4: NOT has higher precedence than AND
IF NOT A AND B THEN
    // means: (NOT A) AND B  -- NOT applied to A first
ENDIF

When in doubt, use parentheses to make your intended order explicit. Even if the default precedence would give the same result, parentheses make the code easier to read and remove ambiguity for both you and the examiner.

8.5 Combining Operators

Real-world conditions rarely use a single operator. You will often combine arithmetic, relational, and logical operators in one expression — for example, to check whether a value falls in a range, or to test multiple criteria at once. The key is to read the expression using the precedence rules and to use parentheses liberally for clarity.

Range Check

To check if X is between 1 and 10 inclusive:

X >= 1 AND X <= 10

Note: you CANNOT write 1 <= X <= 10 in pseudocode — each comparison must be separate.

Even/Odd Test

To check if N is even:

N MOD 2 = 0

If the remainder when dividing by 2 is 0, the number is even.

Example: A Complete Grading Program
DECLARE Score : INTEGER
DECLARE Attendance : INTEGER

INPUT Score
INPUT Attendance

// Combining arithmetic, relational, and logical operators
IF Score >= 80 AND Attendance >= 90 THEN
    OUTPUT "Grade A with excellent attendance"
ELSE
    IF Score >= 50 AND (Attendance >= 50 OR Score >= 90) THEN
        OUTPUT "Pass"
    ELSE
        OUTPUT "Fail"
    ENDIF
ENDIF

// Using MOD to check for multiples
IF Score MOD 10 = 0 THEN
    OUTPUT "Score is a multiple of 10"
ENDIF

Tip: Trace Step-by-Step

When faced with a complex expression, evaluate it in precedence order: first any parentheses, then arithmetic (* / MOD DIV before + -), then relational, then NOT, AND, OR. Write down each intermediate value to avoid mistakes.

8.6 Key Points Summary

Here is a quick recap of everything we've covered on operators:

  • Six arithmetic operators+, -, *, /, DIV, MOD. Use / for REAL division, DIV for integer quotient, MOD for remainder.
  • Relational operators return BOOLEAN=, <>, <, >, <=, >= always produce TRUE or FALSE. They are the basis of every condition.
  • = is comparison, <- is assignmentIn CIE pseudocode the single = asks "are these equal?" while <- stores a value. Do not confuse them.
  • Three logical operatorsAND (both true), OR (at least one true), NOT (inverts a single boolean). Memorise their truth tables.
  • Precedence order: PARLParentheses, Arithmetic, Relational, Logical. Within arithmetic: * / MOD DIV before + -. Within logical: NOT, AND, OR.
  • Use parentheses for clarityWhen combining operators, parentheses make your intended order explicit and avoid precedence bugs.

Question Bank

Read each question, think about your answer, then click "Reveal Answer" — 12 questions

Q1Structured

What does the MOD operator do? Give an example.

Q2Fill

Evaluate: 23 MOD 7 = ____

Q3Structured

Explain the difference between the / operator and the DIV operator in CIE pseudocode.

Q4MC

Which relational operator means "not equal to" in CIE pseudocode?

A!=
B<>
C~=
DNEQ
Q5Structured

What data type does a relational expression such as (Age >= 18) return? Explain why.

Q6Structured

Evaluate the following expression step by step: TRUE AND (FALSE OR TRUE)

TRUE AND (FALSE OR TRUE)
Q7Structured

List the operator precedence order in CIE pseudocode, from highest to lowest.

Q8T/F

In CIE pseudocode, the = symbol is used for comparison (not assignment).

ATRUE
BFALSE
Q9Fill

Evaluate: 17 DIV 3 = ____

17 DIV 3
Q10Structured

What does the expression NOT (5 > 3) evaluate to? Show your working.

NOT (5 > 3)
Q11Structured

Write a CIE pseudocode condition to check whether the variable Age is between 13 and 19 inclusive (i.e. a teenager).

Q12T/F

AND has higher precedence than OR in CIE pseudocode.

ATRUE
BFALSE
Previous: Nested IF
You've reached the end of the Operators topic.
Next: FOR Loop