levo

Defining Data: Types, Variables and Classes

Relational and logical operators

  • 3 things to know
  • AS Unit 1
Start revising · £5/month

Overview

Value does a relational expression produce and short-circuit evaluation.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Key term

What is short-circuit evaluation?

Key term

Explain why if (count != 0 && total / count > 5) is safe but reversing the two conditions is not.

Key term

Explain the difference between the logical AND written with two ampersands and the version written with one.

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    Which six relational operators are there, and what does each test?

    Model answer

    The relational operators test equal to, not equal to, less than, greater than, less than or equal to, and greater than or equal to.

  2. 2

    What type of value does a relational expression produce?

    Model answer

    A relational expression produces a boolean result, either true or false.

  3. 3

    Explain the difference between = and == in Java, and say what the compiler does with if (x = 5) where x is an int.

    Model answer

    A single equals sign assigns a value while a double equals sign tests for equality; Java rejects if (x = 5) because the assignment yields an int and the condition of an if must be a boolean.

  4. 4

    Which three logical operators are there, and what does each do?

    Model answer

    Logical AND is true only when both operands are true, logical OR is true when at least one operand is true, and logical NOT reverses the truth of a single operand.

  5. 5

    Given boolean a = true; boolean b = false; state the values of a && b, a || b and !a.

    Model answer

    The expression a && b is false because one operand is false, a || b is true because one operand is true, and !a is false because a is true.

  6. 6

    What is short-circuit evaluation?

    Model answer

    Short-circuit evaluation stops as soon as the result of a logical expression is settled, so the right operand of an AND is skipped when the left is false, and the right operand of an OR is skipped when the left is true.

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.

Software and the Development Environment
Defining Data: Types, Variables and Classes
Program Control Structures
Objects, Classes and Data Structures

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 null is the of one.
absencepresencetype

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.

An error is the mistake a person made.
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 Defining Data: Types, Variables and Classes, 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.