Skip to main content
Engineering LibreTexts

6.9: Multidimensional Arrays

  • Page ID
    10696
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Overview

    The number of indices needed to specify an element is called the dimension or dimensionality of the array. A two-dimensional array, or table, may be stored as a one-dimensional array of one-dimensional arrays (rows of columns) and accessed with double indexing (array[row][column] in typical notation).[1]

    Discussion

    An array is a sequenced collection of elements of the same data type with a single identifier name. As such, the array data type belongs to the “Complex” category or family of data types. Arrays can have multiple axes (more than one axis). Each axis is a dimension. Thus a single dimension array is also known as a list. A two-dimension array is commonly known as a table (a spreadsheet like Excel is a two dimension array). In real life, there are occasions to have data organized into multiple dimensioned arrays. Consider a theater ticket with section, row, and seat (three dimensions).

    We refer to the individual values as members (or elements) of the array. Multidimensional arrays use one set of square brackets per dimension or axis of the array. For example, a table which has two dimensions would use two sets of square brackets to define the array variable and two sets of square brackets for the index operators to access the members of the array. Programming languages implement the details of arrays differently. The total number of dimensions allowed in an array is language-specific and also limited by available memory.

    Pseudocode

    Function Main
        Declare String Array game[3][3]
        
        Assign game = [ ["X", "O", "X"], ["O", "O", "O"], ["X", "O", "X"] ]
    
        DisplayGame(game)
    End
    
    Function DisplayGame (String Array game)
        Declare Integer row
        Declare Integer column
        
        Output "Tic-Tac-Toe"
        For row = 0 to 2
            For column = 0 to 2
                Output game[row][column]
                If column < 2 Then
                    Output " | "
                End
            End
        End
    End
    

    Output

    Tic-Tac-Toe
    X | O | X
    O | O | O
    X | O | X
    

    Key Terms

    array member
    An element or value in an array.
    dimension
    An axis of an array.
    index
    An operator that allows us to reference a member of an array.
    list
    A single dimension array.
    offset
    The method of referencing array members by starting at zero.
    table
    A two-dimension array.

    6.9: Multidimensional Arrays is shared under a CC BY-SA 4.0 license and was authored, remixed, and/or curated by LibreTexts.

    • Was this article helpful?