Skip to main content
Northern IrelandSoftware Systems DevelopmentSyllabus dot point

What data types, variables, constants and operators does an object oriented program use, and when is type conversion needed?

Primitive data types, variables and constants, arithmetic, relational and logical operators, operator precedence, and type conversion (casting).

A CCEA A-Level Software Systems Development answer on primitive data types, declaring variables and constants, arithmetic, relational and logical operators with precedence, and type conversion or casting.

Generated by Claude Opus 4.812 min answer

Reviewed by: AI editorial process; not yet individually human-reviewed

Have a quick question? Jump to the Q&A page

Jump to a section
  1. What this dot point is asking
  2. The answer
  3. Examples in context
  4. Try this

What this dot point is asking

CCEA wants you to choose appropriate data types for stored values, declare and use variables and constants, and apply arithmetic, relational and logical operators with the correct precedence. You also need to understand type conversion (casting), including implicit widening and explicit narrowing, and the problems that arise when types are mixed. Questions ask you to pick types, trace expressions, and explain conversions.

The answer

Data types

Choosing the right type matters: money and measurements need a real type, counts and indices need an integer, yes/no flags need a Boolean, and text needs a string. Using the wrong type wastes memory or loses information (for example storing a price as an integer drops the pence).

Variables and constants

A variable is a named memory location whose value can change while the program runs. A constant is a named value that is fixed at declaration and cannot be reassigned. Constants are conventionally written in upper case (VAT_RATE, MAX_SIZE).

Operators and precedence

Three families of operator are examined:

  • Arithmetic: +, -, *, /, integer division DIV and remainder MOD (modulus).
  • Relational (comparison): = or ==, <> or !=, <, >, <=, >=, each yielding a Boolean.
  • Logical: AND, OR, NOT, combining Boolean values.

Type conversion (casting)

Type conversion changes a value from one type to another. Implicit (automatic) conversion, or widening, happens safely when a narrower type fits into a wider one, for example an integer used where a real is expected. Explicit conversion (casting), or narrowing, is requested by the programmer, for example (int) 7.9, and can lose information (the result is 7, the fractional part is discarded).

Worked example: choosing types and tracing an expression

Examples in context

Example 1. A temperature converter. A program reads a Celsius value as a real, applies fahrenheit = celsius * 9 / 5 + 32, and stores the result as a real. Using integer types here would lose decimals and give wrong answers; the precedence of * and / before + is essential to the formula.

Example 2. A login attempt counter. An integer attempts starts at 0 and increases each time a password is wrong; a constant MAX_ATTEMPTS = 3 sets the limit. A relational test attempts >= MAX_ATTEMPTS combined with a Boolean locked controls whether the account is blocked, showing variables, a constant and relational and logical operators working together.

Try this

Q1. State a suitable data type for each: a person's age, their height in metres, and whether they are a member. [3 marks]

  • Cue. Age is an integer, height is a real (float/double), membership is a Boolean.

Q2. Explain one benefit of using a named constant rather than writing the literal value 0.2 directly in code. [2 marks]

  • Cue. A named constant (such as VAT_RATE) is self-documenting and can be changed in one place, improving readability and maintainability.

Q3. Evaluate (int) (10 / 4) and explain the result. [2 marks]

  • Cue. Integer division of 10 by 4 gives 2 (remainder discarded), and the cast confirms an integer result, so the value is 2.

Exam-style practice questions

Practice questions written in the style of CCEA exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.

CCEA 20195 marksA program stores a price, a quantity and whether an item is in stock. State a suitable data type for each, and explain the difference between a variable and a constant.
Show worked answer →

The price should be a real or floating-point type (such as double or float) because it can hold a decimal value like 12.99. The quantity should be an integer (int) because it counts whole items. Whether an item is in stock should be a Boolean, holding only true or false.

A variable is a named store whose value can change while the program runs, for example quantity is reduced as items are sold. A constant is a named store whose value is fixed when declared and cannot be changed afterwards, for example a VAT_RATE of 0.2 or MAX_ITEMS. Constants are usually written in upper case and are used so that a fixed value appears once and has a meaningful name, which improves readability and makes maintenance safer.

Markers reward the correct type for each of the three values, and a clear variable-versus-constant distinction (changeable versus fixed) with a sensible example.

CCEA 20214 marksEvaluate the expression 5 + 3 * 2 > 10 AND 4 < 6, explaining the order in which the operators are applied.
Show worked answer →

Operators are applied in order of precedence: arithmetic first, then relational, then logical. Working through it:

5 + 3 * 2 > 10 AND 4 < 6
= 5 + 6 > 10 AND 4 < 6     (multiplication first: 3 * 2 = 6)
= 11 > 10 AND 4 < 6         (then addition: 5 + 6 = 11)
= true AND true             (then the two relational comparisons)
= true                      (finally the logical AND)

So the expression evaluates to true. The key is that * binds tighter than +, both bind tighter than the relational operators > and <, and the logical AND is applied last of all.

Markers reward the correct final value true and a correct precedence order: arithmetic (multiplication before addition), then relational comparisons, then the logical operator.

Related dot points

Sources & how we know this