How to Declare 3-Dimensional Arrays in Wiring in C?
Prerequisite: Array in C
Arrays are used the make a list of the same data type elements and store it in contiguous memory locations. In simple words, arrays are the organization of elements of the same data types. There are many types for declaring the array i.e, 1-Dimensional arrays, 2-Dimensional arrays, and 3-Dimensional arrays.
What is Wiring?
Wiring is the concept that shows the array connected with each other and forming a new 3-Dimensional array.
3-Dimensional Array
A collection of 2-dimensional arrays, stored sequentially in storage locations in the array is called a 3-Dimensional array.
Wiring related to a 3-D array:
The original meaning of the wiring is connecting the things and also in the 3-Dimensional array it works the same, it is used for connecting the array and making the new Three-dimensional structure. Every block/element of the array is connected with each other.
In this article, we are discussing 3-dimensional arrays which are organized in the form of wiring. These 3-dimensional arrays in wiring are like matrix declarations in the array.
Example:
C
#include <stdio.h>
int main()
{
int i, j, k;
int arr[3][3][3] = {
{ { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } },
{ { 11, 12, 13 }, { 14, 15, 16 }, { 17, 18, 19 } },
{ { 21, 22, 23 }, { 24, 25, 26 }, { 27, 28, 29 } },
};
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
for (k = 0; k < 3; k++) {
printf ( "%d" , arr[i][j][k]);
printf ( "\t" );
}
printf ( "\n" );
}
printf ( "\n" );
}
return 0;
}
|
Output
1 2 3
4 5 6
7 8 9
11 12 13
14 15 16
17 18 19
21 22 23
24 25 26
27 28 29
Last Updated :
29 Nov, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...