C++ Two dimension (2D) Array

Two dimension (2D) array is an array of arrays. It is represented in the form of row and column. The elements of 2D array are accessed through the index of row and column.

Declaration of 2D Array

In the above declaration, data_type is C++ data type, array_Name is the name of array and size_row is the total size of row and size_column is total size of the column of array elements.

Initialization of 2D Array

A 2D array is initialized with data type followed by array name and total row size and column size of elements assignment into array.

Another best way to initialize the 2D array is as follow:

Access of Array

Elements of an array are accessed through the index (indices) of that element. The index of array starts from[00] and end at [row_size-1column_size-1] of array.

Suppose we want to access the individual elements of a 2D array, this can be done by passing index of the element in array name.

Two dimension Array example

Two dimension array are accessed by using two loops (nested loop). The external loop access row of array whereas inner loop access column of the array.


Pin It on Pinterest

Share This