0% found this document useful (0 votes)
7 views14 pages

Understanding Two Dimensional Arrays

A two-dimensional array is a table-like structure consisting of rows and columns, allowing for the storage of data in a grid format. It differs from a one-dimensional array, which only requires a single index for access, while a two-dimensional array requires both row and column indices. The document also discusses the creation and initialization of two-dimensional arrays in C++, highlighting their use for storing homogeneous data types.

Uploaded by

eric.e.aghedo
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views14 pages

Understanding Two Dimensional Arrays

A two-dimensional array is a table-like structure consisting of rows and columns, allowing for the storage of data in a grid format. It differs from a one-dimensional array, which only requires a single index for access, while a two-dimensional array requires both row and column indices. The document also discusses the creation and initialization of two-dimensional arrays in C++, highlighting their use for storing homogeneous data types.

Uploaded by

eric.e.aghedo
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Two Dimensional Array

Visual Representation of a two


dimensional Array
• It is an array that can be described as table having both row and
column
A two dimensional array [row]
[column]

[0][0] [0][1] [0][2]

[1][0] [1][1] [1][2]

[2][0] [2][1] [2][2]


Comparing one dimensional and two
dimensional array
• A one dimensional array can be created by indicating the number of
elements it contains
• Int array[5];
• BUT a two dimensional is created by indicating number of rows and
columns it has
• int array[2][3]
Comparing one dimensional and two
dimensional array
• A one dimensional array can be referenced or accessed by indicating
just the row index
• If there is an array such as array[4]={1, 5, 7, 9};
• To access 7 we indicate the index of 7
• array[rowindex]; e.g., array[2];
• A two dimensional array is referenced or accessed by indicating the
row and column index
• If there is an array such that array[2][2]={{2,3},{5,8}};
• To access 5 we indicate the row index which is 1 and the column index which
is 0 (using zero based indexing)
Using CPP to create a two
dimensional array
• To create includes:
• Declaration
• Initialization
• These can be done
• Statically
• Dynamically
Array Creation
• Note that an array has homogenous data type such as
• Int
• Float
• Double
• Char
• Basically we use an array when we want to store elements of the
same data type in a single variable such that one will not overwrite
the other
• E.g. to store scores of all the students in a class
Array Creation
• When it comes to two dimensional array, we can store
• Score of a number of students in different courses
• E.g., score of 8 students offering 5 courses
• This will be int score[8][5];
Output
Output
Dynamic Creation

You might also like