<< Chapter < Page Chapter >> Page >
An introduction and example of multidimensional arrays as used within the C++ programming language.

Overview

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. Programming languages implement the details of arrays differently. Because there is only one identifier name assigned to the array, we have operators that allow us to reference or access the individual members of an array.

The operator commonly associated with referencing an array member is the index operator. It is important to learn how to define an array and initialize its members. The index operator is a set of square brackets with an integer value between the brackets that represents the offset from the front 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.

Because of the complexity for multidimensional arrays, the demonstration program shows a two dimension array and you should study it in conjunction with this module.

Demonstration program in c++

Creating a folder or sub-folder for source code files

Depending on your compiler/IDE, you should decide where to download and store source code files for processing. Prudence dictates that you create these folders as needed prior to downloading source code files. A suggested sub-folder for the Bloodshed Dev-C++ 5 compiler/IDE might be named:

  • Demo_Programs

If you have not done so, please create the folder(s) and/or sub-folder(s) as appropriate.

Download the demo program

Download and store the following file(s) to your storage device in the appropriate folder(s). Following the methods of your compiler/IDE, compile and run the program(s). Study the source code file(s) in conjunction with other learning materials. You may need to right click on the link and select "Save Target As" in order to download the file.

Download from Connexions: Demo_Multidimension_Arrays.cpp

Definitions

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

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Programming fundamentals - a modular structured approach using c++. OpenStax CNX. Jan 10, 2013 Download for free at http://cnx.org/content/col10621/1.22
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Programming fundamentals - a modular structured approach using c++' conversation and receive update notifications?

Ask