Operators, library routines and string handling Cambridge IGCSE Computer Science revision

Not started

Learn it

In plain words

Operators are the symbols that do the work in a program: they calculate, compare and combine. Library routines are ready-made pieces of code for common jobs. String handling is working with text.

6 things to know

  1. Arithmetic operators: + add, − subtract, * multiply, / divide, ^ raise to a power. So 2 ^ 3 is 8.
  2. DIV gives the whole-number part of a division and MOD gives the remainder. DIV(17, 5) is 3 and MOD(17, 5) is 2.
  3. Relational operators compare two values and give TRUE or FALSE: = equal to, <> not equal to, < less than, <= less than or equal to, > greater than, >= greater than or equal to.
  4. Logical operators: AND is true only when both conditions are true. OR is true when at least one is true. NOT reverses true and false.
  5. Library routines: MOD, DIV, ROUND and RANDOM. ROUND(3.14159, 2) gives 3.14. RANDOM() gives a random number between 0 and 1.
  6. String handling: LENGTH("Hello") is 5. UCASE("Hello") is "HELLO" and LCASE("Hello") is "hello". SUBSTRING("Computer", 1, 3) is "Com": three characters starting from position 1.

Worked example

A program must decide whether Number is even. Write the condition.

  1. An even number divides by 2 with no remainder.
  2. MOD gives the remainder: MOD(Number, 2).
  3. The condition is MOD(Number, 2) = 0.

Tips and tricks

  • DIV and MOD go together: DIV is how many whole times it goes in, MOD is what is left over. 17 = 3 × 5 + 2.
  • The first character of a string can be position 0 or position 1. The question will say which. Here it is 1.
7 questions, about 2 minutes.

It lands in your notebook with its questions as flashcards.

Operators, library routines and string handling: 7 questions and answers

These are the quiz’s questions. Do the quiz first, then come back here for the ones that got you.

  1. What is the value of MOD(20, 6)?
    • 2 (the answer)
    • 3
    • 6
    • 14

    6 goes into 20 three times, with 2 left over.

  2. What is the value of DIV(20, 6)?
    • 2
    • 3 (the answer)
    • 4
    • 14

    The whole-number part of 20 ÷ 6.

  3. What is the value of 2 ^ 4?
    • 6
    • 8
    • 16 (the answer)
    • 24

    2 × 2 × 2 × 2.

  4. What is the value of LENGTH("Octopus")?
    • 6
    • 7 (the answer)
    • 8
    • 1

    Count the characters.

  5. The first character is position 1. What is SUBSTRING("Octopus", 1, 4)?
    • "Oct"
    • "Octo" (the answer)
    • "ctop"
    • "opus"

    Four characters, starting at the first.

  6. What is the result of (5 > 3) AND (2 > 4)?
    • TRUE
    • FALSE (the answer)
    • 5
    • an error

    AND needs both to be true, and 2 > 4 is false.

  7. Which operator means "not equal to"?
    • =
    • >=
    • <> (the answer)
    • ^

    For example, Guess <> Answer.

Still stuck on this one?Ask in the Papermunch Discord, or help someone else who is. Discord is for ages 13 and up.Join the server

Things you can type

Or go straight to

Or browse a shelf