3-D Array

Jun 13, 2012 at 11:04am
3-D array
a[2][3][2]

0th 2-D array
elements address
2 104
4 106
7 108
8 110
3 112
4 114

1st 2-D array
2 116
2 118
2 120
3 122
3 124
4 126


*a +1 =108
**a +1 =106
***a +1 =3

How????
Please Help!
Jun 13, 2012 at 11:20am
Could you repeat the same but using human language?!
Last edited on Jun 13, 2012 at 11:21am
Jun 13, 2012 at 11:37am
There is a 3 dimensional integer array a.
It is as
int a[2][3][2]= {
{
{2,4},
{7,8},
{3,4}
},

{
{2,2},
{2,3},
{3,4}
}
};

Address of each element has been mentioned above

printf("%u\n",*a +1);
printf("%u\n",**a +1);
printf("%u\n",***a +1);

outputs as

108
106
3

Now you'll understand vlad this human language i think :)










Jun 13, 2012 at 12:01pm
And what do you want? Do you want to know how these results were obtained?
Also it seems you use DOS where integers have size of 2 bytes.

Well I will try to explain.

The element of n-dimensional array is an array of dimension n-1.

So *a - is a two-dimensional array;
**a - is a one-dimensional array;
***a - is a scalar object.

In expressions arrays are converted to a pointer to the first element. So in the expression
*a +1

*a is the two-dimensional array

{2,4},
{7,8},
{3,4}

In the expression *a is converted to a pointer to its frist element that is int ( * )[2] and points to the array

{2,4}

*a + 1

will point the next one-dimensional array that is
{7,8}

Let consider the next expression
**a + 1

**a is the one dimensional array

{2,4},
in the expression **a + 1 the operand **a is converted to the address of the first element of the array, that is the address of element which has value 2. After addition 1 it will point the next element that is 4.

So compare *a + 1points to 7, while **p + 1 points to 4. It means that your integer objects have size of 2 bytes.

Now consider the third expression ***a + 1
***a is an object of type int and equal to 2 (the fiirst element). After adding 1 (2 + 1 ) it has value equal to 3.

That is all.
Last edited on Jun 13, 2012 at 12:27pm
Jun 13, 2012 at 1:17pm
gud explain....i got it
thanks a lot :)
Topic archived. No new replies allowed.