Two Dimensional Array in C++
Two Dimensional array can be defined as a multidimensional array in C++ program. Two Dimensional Array represented as the collection of rows and columns.
Declaration of Two Dimensional Array:
To declare the 2D array in C++ programming language.
Syntax:-
Data_type Array_name[Row_size][Column_size];
Example:-
int a[3][2];
Here, a is Two-dimensional array, this array can hold 6 elements.
Initialization of Two Dimensional Array:
Multidimensional arrays initialized by specifying bracketed values for every row.
int score[3][2] = {{100, 221}, {59, 54},{10, 21}};
Example:-
#include <iostream>
using namespace std;
int main(){
// 3 rows & 2 columns
int score[3][2] = {{100, 221}, {59, 54},{10, 21}};
for(int i=0; i<3; i++){
for(int j=0; j<2; j++){
cout << " Element[" << i << "][" << j << "]= " << score[i][j] << endl;
}
}
return 0;
}
Quickly Find What You Are Looking For
OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.