levo

Fundamentals of Programming

Data types

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

Overview

Recall questions on the integer, real, Boolean, character and string types, why each variable is declared with one, and why the character '7' is not the number 7.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Key term

A program counts how many pupils are in a room. Explain why integer is a better choice of type than real.

Evaluation

Describe the Boolean data type.

Key term

What is a user-defined data type?

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    What is a data type?

    Model answer

    A data type defines the set of values a variable of that type may hold, the operations that may legally be performed on it, and how the value is represented in memory. Declaring a type tells the translator how much memory to reserve for the variable and how to interpret the bit pattern stored there.

  2. 2

    Give three reasons why declaring the data type of every variable is useful.

    Model answer

    The translator can reserve the correct amount of memory and interpret the stored bit pattern correctly, and it can detect type errors before the program runs, for example an attempt to subtract one string from another. Declared types also document the programmer's intention for anyone later reading or maintaining the code.

  3. 3

    Describe the integer data type.

    Model answer

    A whole number with no fractional part, which may be positive, negative or zero — −7, 0 and 4096 are all integers. Unlike a real, an integer is held exactly, so comparing two for equality is safe and no rounding error accumulates. The arithmetic available on integers is the ordinary four operations, together with the pair that only makes sense for whole numbers: integer division, which discards any fraction, and the remainder that division leaves behind.

  4. 4

    Describe the real (float) data type.

    Model answer

    A number that may have a fractional part, for example 3.14 or -0.5. It is normally stored as a mantissa together with an exponent, so only a limited number of significant digits is kept and most real values are held as a close approximation rather than exactly.

  5. 5

    A program counts how many pupils are in a room. Explain why integer is a better choice of type than real.

    Model answer

    The value can only ever be a whole number, so an integer represents it exactly, occupies less memory and is faster to work with. A real would permit meaningless values such as 27.4 and, because reals are stored approximately, a test such as count = 27 could fail even when the count really is twenty-seven.

  6. 6

    Describe the Boolean data type.

    Model answer

    A type with exactly two possible values, True and False. It is what a relational or logical expression evaluates to, and it is used to control selection and iteration. Logically it needs only a single bit, although a language will usually reserve a whole byte for it.

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.