Multi-dimensional arrays

Array in C can have  virtually as many dimension as you want. Multi-dimensional arrays have two or more index values which are used to specify a particular element in the array.

int arr[i][j]

Here the first index value i specifies a row index, while j specifies a column index.

Declaring multi-dimensional arrays is similar to the 1D case:

int arr[10];     /* declare 1D array */

float arr_1[3][5];     /* declare 2D array */

double arr_2[6][4][2];     /* declare 3D array */


int arr[4][3];     /* Declare 2D array of row size 4 and colomn size 3*/

Initialization of 2D array

int arr[4][3] = {{1,2,3},{4,5,6},{7,8,9},{10,11,12}};

Also can be done by

int arr[4][3] = {1,2,3,4,5,6,7,8,9,10,11,12};

Now i want to access the value at 3rd row and 2nd colomn

arr[2][1];     /* The value is ‘8’ */

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.