Wednesday, 1 March 2017

Three-Dimensional Array in c

We wouldn't demonstrate a programming illustration that uses a three-dimensional array. This is on account of, practically speaking, one seldom utilizes this array. In any case, a case of instating a three-dimensional
an array will merge your comprehension of subscripts:

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


A three-dimensional array can be considered as a variety of array 

of arrays. The external array has three components, each of which is a 

two-dimensional array of four one-dimensional arrays, each of 

which contains two whole numbers. As it were, a one-dimensional 

an array of two components is built first. At that point, four such one-dimensional arrays are put one beneath the other to give a two-dimensional array containing four lines. At that point, three such two-dimensional arrays are set one behind the other to yield a three-dimensional array containing three 2-dimensional arrays. In the 

array statement takes note of how the commas have been given. Figure 


8.9 would potentially help you in envisioning the circumstance better.



Three-Dimensional Array in c





Again recollect that the game plan appeared above is as it were 

reasonably genuine. In memory, similar array components are put away 


directly as appeared in Figure 8.10.




Three-Dimensional Array in c




How would you refer to the array element 1 in the above array?
The first subscript should be [2], since the element is in third twodimensional array; the second subscript should be [3] since the
element is in fourth row of the two-dimensional array; and the
third subscript should be [1] since the element is in second position
in the one-dimensional array. We can therefore say that the
element 1 can be referred as arr[2][3][1]. It may be noted here that
the counting of array elements even for a 3-D array begins with
zero. Can we not refer to this element using pointer notation? Of
course, yes. For example, the following two expressions refer to

the same element in the 3-D array:

arr[2][3][1]

*( *( *( arr + 2 ) + 3 ) + 1 )


Summary

1)   An array is like a customary variable aside from that it can 

store various components of comparable sort.

2)   Compiler doesn’t perform bounds checking on an array.

3)   The array variable goes about as a pointer to the zeroth component of 

4)   the exhibit. In a 1-D exhibit, zeroth component is a solitary esteem, 

while, in a 2-D cluster this component is a 1-D exhibit.


5)   On incrementing a pointer it points to the next location of its

type

6)   array components are put away in touching memory areas 

thus they can be gotten to utilizing pointers.

7)   Only limited arithmetic can be done on pointers.

0 comments:

Post a Comment