levo

Fundamentals of Programming

Data types

  • 3 things to know
  • Paper 1

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.

What is inside Levo

Six ways to work the same material.

1Closed book
2Open book
3Closed book

The 3-step method, run for you

Answer cold, learn it, then prove it stuck. Levo tracks the jump between your first attempt and your last.

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

Cram a whole paper in one sitting

Sort every topic into what you know and what you do not, then drill only the weak ones.

A driver is .
softwarehardwarestorage

Blank Blitz makes facts automatic

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

AThe integer 5 is 0101.
B0.75 is 1/2 + 1/4.
CThe fraction bits are 1100.

Build It gets the exam shape right

Assemble a full-mark answer from its marking points, in the order an examiner wants them.

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

Test It catches misconceptions

Spot the fault in a statement. The traps are the mistakes students actually make.

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.

Attempt a question from memory, write the correct version, then attempt it again. Levo records the jump between your first attempt and your last, and brings each question back on the day you are due to forget it.

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