levo

Fundamentals of Programming

Relational Operations, Constants and Variables

  • 4 things to know
  • Paper 1
Start revising · £5/month

Overview

Recall questions on the six relational operations and their symbols, the result they yield, and the distinction between assignment and comparison.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Key term

Why is testing two real numbers for exact equality unreliable, and what should you do instead?

Evaluation

A is True and B is False. Evaluate NOT A, A AND B, A OR B and A XOR B.

Key term

Explain the difference between a variable and a constant.

Key term

Give an example of a constant and of a variable, and say why naming a limit helps.

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    Name the six relational operations and give a symbol commonly used for each.

    Model answer

    Equal to (= or ==), not equal to (!= or <>), less than (<), greater than (>), less than or equal to (<=), and greater than or equal to (>=).

  2. 2

    What is the result of a relational operation, and what is it used for?

    Model answer

    A Boolean value, True or False. That Boolean result is what a selection statement or the condition of a loop tests, and it can also be stored in a Boolean variable or combined with other conditions using Boolean operators.

  3. 3

    Why do many languages use = for one purpose and == for another?

    Model answer

    Because assigning and comparing are different operations. In C#, Java and Python a single = assigns a value to a variable while a double == tests two values for equality; VB.Net uses = for both and works out which is meant from the context. Writing = where == is meant is a common error that either fails to compile or silently changes a variable.

  4. 4

    How do you test that a mark is at least 40 but no more than 69?

    Model answer

    mark >= 40 AND mark <= 69. 'At least' maps to greater than or equal to, and 'no more than' maps to less than or equal to; using the strict < and > operators here would wrongly exclude the boundary values 40 and 69.

  5. 5

    How are two strings compared by the relational operators, and is 'Zoo' less than 'apple'?

    Model answer

    They are compared character by character from the left using the character codes, and the first position where they differ decides the outcome; if one string runs out first it is the smaller. In ASCII the capitals occupy codes 65 to 90 and the lower-case letters 97 to 122, so 'Z' (90) is less than 'a' (97) and therefore 'Zoo' is less than 'apple'. This is why a case-sensitive sort puts all capitalised words before lower-case ones.

  6. 6

    Why is testing two real numbers for exact equality unreliable, and what should you do instead?

    Model answer

    Because reals are stored as an approximation, so a value that should be 0.3 may be held as very slightly more or less and a test for exact equality then fails. Instead test that the difference is smaller than a small tolerance, for example abs(a - b) < 0.000001. Integers are stored exactly, so testing them for equality is perfectly safe.

Other ways to work this

The same content, four other ways.

Everything in your subscription

Runs, plus a mode for every other kind of session.

1Flash
2Imposter
3Fade
4Brain dump

Learn every subtopic in runs of four questions

Facts flash and fade, a wrong word hides in some of them, and a brain dump decides which questions are locked in.

Fundamentals of Programming
Fundamentals of Data Structures
Fundamentals of Algorithms
Theory of Computation

Cram the night before, weakest topic first

A quick scan finds your weakest topics. Recall each fact you missed three times in a row.

A driver is .
softwarehardwarestorage

Blank Blitz consolidates the facts

Rapid timed gap-fills on the terms and numbers you need to recall without thinking.

✓What it iscovered
~Why it happenspartly there
How long it lastsnot there yet

Explain It tests your understanding

Explain a concept in your own words and see which of its points you covered.

Head means the first single element of a non-empty list.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The faults are the mistakes students make most often.

721941163128510

Brain Breaks between sessions

Short focus games to reset attention, so the next set lands better than the last.

Every question in Fundamentals of Programming, on a schedule.

Learn it in runs of four questions, each ending on a brain dump against the clock. Every question you lock in comes back the next day, then at longer gaps, each time just before you would forget it.

Or £46 a year, about £3.83 a month. Cancel anytime.