A-level Computer Science revision · Programming

Data types, strings and arrays

The idea

Common data types are integer, real (float), Boolean, character and string. Casting converts between types. String operations include length, substring and concatenation. Arrays hold many values of the same type, accessed by index, usually from 0. Files are opened, read or written, and closed.

  1. Choose the type that fits the data.
  2. Remember zero-indexing: the first element is index 0.
  3. Use casting before arithmetic on input strings.

Watch out In a zero-indexed array of length n, the last index is n − 1.

See it worked

Worked example

names = ['Ali', 'Bo', 'Cy']. What is names[2]?

  1. Indexing starts at 0.
  2. names[0] = Ali, names[1] = Bo, names[2] = Cy.

Answer 'Cy'

Your turn

Question 12 marks

An array has 12 elements, indexed from 0. What is the index of the last element?

Question 21 mark

Which data type is best for storing a telephone number such as 07700900123?

Choose one
Question 31 mark

word = 'COMPUTER'. What is word.length?

Choose one

A-level Computer Science Pro, OCR H446

A-level Computer Science Pro

£119 once

Price rises to £199 on 1 January. Save £80 by joining before then.

At least 12 months of access

By paying you agree to our Terms and get access straight away, which ends your 14-day cancellation right.

No VAT is charged.

Independent practice for OCR A-level Computer Science (H446), not endorsed by OCR.

Privacy · Terms