-moz-user-select:none; -webkit-user-select:none; -khtml-user-select:none; -ms-user-select:none; user-select:none;

Saturday, 15 August 2015

Initialization of 2-d arrays in C++

Initializing 2-dimensional array

The 2-D arrays which are declared by the keyword int and able to store integer values are called two dimensional integer arrays. The process of assigning values during declaration is called initialization. TheseArrays can be initialized by putting the curly braces around each row separating by a comma also each element of a matrix should be separated by a comma.

Example: 

int mat[3][3]={ {2,3},{4,5},{6,7} }

Initializing 2-d character array

The 2-D arrays which are declared by the keyword char and able to store characters are called two dimensional character arrays. 2-D character array can be initialized by putting the curly braces around each row as well as apostrophe around every alphabet.

Example:

char character[3][3]={'b', 'a' ,'t' ,'f', 'a' ,'t' ,'m' ,'a' ,'t'};

reference

The reference of this article is taken from


In my next blog inshAllah,I will post an important example of 2-d arrays that will be very helpful in understanding this concept.So,stay tuned.

No comments:

Post a Comment