Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/myscript/public_html/classes/classdb.php on line 42
Multi Dimensional Arrays - C++ Tutorial

Multi Dimensional Arrays

What is Multi Dimensional array in C++?

Explanation

The Multi Dimensional Array is an array with two or more index values. It is also known as array of arrays. A two dimensional array is also a multi dimensional array.

Syntax:


type array_name[array_size_1][array_size_2]..[array_size_n]

Example :



#include <iostream.h>
void main()
{
int i,j;
char achar[2] [2] = {'A','r','r','a'};
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cout << "Row:: "<< i+1 << "s column::"<<
j+1 <<" element is:: "<< achar[i][j]<< '\n';
}
}
}

Result :

Row:: 1s column::1 element is :: A
Row:: 1s column::2 element is :: r
Row:: 2s column::1 element is :: r
Row:: 2s column::2 element is :: a

In the above example, the character array "achar" is used to display elements of rows, columns using a loop.

C++ Tutorial


Ask Questions

Ask Question