Array in C language
An array is collection of elements having same data type. It is holds multiple value with same name and accessible using index value. It can be of any data type either built-in or custom data type.
1. One dimension2. Two dimension3. Three dimension

One dimension array

A one dimension array define and store value in single dimension and can be access using index value. It is declared with single square bracket by specifying the length of array.
1D array
 1 // define 1D array
 2 char arr[3];
 3 int nums[3]
 4 
 5 // define and initialized
 6 char arr[3] = {'a', 'b', 'c'};
 7 int nums[3] = {2, 3, 5};

Two dimension array

A two dimension array define and store value in two dimension and can be access using two axis x and y. It is declared with two square bracket by specifying x length and y length. Each x axis can hold values upto y elements.
2D array
 1 // define 2D array has three string of length 10 each
 2 char str[3][10];
 3 int nums[2][3];
 4 
 5 // declare and initialized 2D array
 6 char str[][] = {{'a', 'b', 'c', '\0'}, {'p', 'q', 'r', '\0'}};
 7 int nums[][] = {{5, 9, 3}, {2, 4, 7}};

Three dimension array

A three dimension array define and store value in three dimension and can be access using three axis x, y and z. It is declared with three square bracket by specifying x length y length and z depth. Each x and y axis can hold values upto z elements.
3D array
 1 // define 3D array
 2 char arr[2][2][1];
 3 int nums[2][2][1];
 4 
 5 // define and initialized
 6 char arr[2][2][1] = {'a', 'b', 'c', 'd'};
 7 int nums[2][2][1] = {3, 5, 2, 8};
Privacy Policy
Terms of Service
Disclaimer
Contact us
About us