Test your knowledge with free interactive questions on Seneca — used by over 10 million students.

Arrays

Arrays are really useful when you have access to large amounts of related data, but you don't want to store in multiple variables.

Arrays

Arrays

  • Arrays are a data structure that stores a fixed number of values under a single identifier.
  • The values must be of the same type.
Array elements

Array elements

  • Each piece of data inside an array is called an element.
  • Each element has an index, which is its position within the array.
  • We start counting the indices from 0.
Arrays in pseudocode

Arrays in pseudocode

  • An array of ten items can be created using the following syntax:
    • array name_of_array[10]
  • Values can be assigned as follows:
    • name_of_array[0] = "Hello"
  • Values can be accessed as follows:
    • print(name_of_array[0])

2D Arrays

A 2D array is the data structure which consists of an array of arrays.

2D Array

2D Array

  • A 2D array is a data structure where arrays are filled with other arrays.
  • This can be used to represent a 2D surface, or records.
Accessing elements

Accessing elements

  • To access an individual array, we can access the array as usual:
    • array = my2DArray[4]
  • To access an individual element, we use this syntax:
    • array[5][0]
  • This would get the first element of the sixth array.
Applications of 2D arrays

Applications of 2D arrays

  • 2D arrays are often used to represent a 2D surface, for example a chess board:
    • Each element of the 2D array could contain the chess piece in that location.
  • 2D arrays can be used to represent a database:
    • The outer array stores a collection of records.
    • The inner arrays store a single record.
Jump to other topics
1

Computer Systems

1.1

Systems Architecture

1.2

Memory & Storage

1.3

Computer Networks, Connections & Protocols

1.4

Network Security

1.5

Systems Software

1.6

Ethical, Legal, Cultural & Environmental Concern

2

Computational Thinking, Algorithms & Programming

2.1

Algorithms

2.2

Programming Fundamentals

2.3

Producing Robust Programs

2.4

Boolean Logic

2.5

Programming Languages & IDEs

Practice questions on Arrays

Can you answer these? Test yourself with free interactive practice on Seneca — used by over 10 million students.

  1. 1
  2. 2
  3. 3
Answer all questions on Arrays

Unlock your full potential with Seneca Premium

  • Unlimited access to 10,000+ open-ended exam questions

  • Mini-mock exams based on your study history

  • Unlock 800+ premium courses & e-books

Get started with Seneca Premium