4.1.4

2D Arrays

Test yourself

2D Arrays

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

Illustrative background for 2D ArrayIllustrative background for 2D Array ?? "content

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.
Illustrative background for Accessing elementsIllustrative background for Accessing elements ?? "content

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.
Illustrative background for Applications of 2D arraysIllustrative background for Applications of 2D arrays ?? "content

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

1Components of a Computer

2Software & Software Development

3Exchanging Data

4Data Types, Data Structures & Algorithms

5Legal, Moral, Cultural & Ethical Issues

6Elements of Computational Thinking

6.1Thinking Abstractly

6.2Thinking Ahead

6.3Thinking Procedurally

6.4Thinking Logically

6.5Thinking Concurrently

7Problem Solving & Programming

8Algorithms

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