# Thread: 2-d array

1. ## 2-d array

i've been stuck on this problem,i hope some1 would be able to help me out..here! by explaning about how did that particular outcome come? the output is coming out to be...1002 1002 1002 1 Any help would be appreciated!
Code:
```main()
{
int a[2][3][4]={
{
1,2,3,4,
5,6,7,8
9,1,1,2
},
{
2,1,4,7,
6,7,8,9
0,0,0,0
}
};
printf("\n%u %u %u %d",a,*a,**a,***a);
}```

2. Your formatting is just horrid.

Because your array is 3D, your array identifier is essentially a pointer of a pointer of a pointer. Which means in order to get the value (The first element of the array) you have to dereference it three times. Hence why the first three output yield a memory address and the last yields the value.

3. Originally Posted by galmca
i've been stuck on this problem,i hope some1 would be able to help me out..here! by explaning about how did that particular outcome come? the output is coming out to be...1002 1002 1002 1 Any help would be appreciated!
[/code]
Code:
```int main(int argc, char **argv)
{
int a[2][3][4]={
{1,2,3,4,5,6,7,8,9,1,1,2},
{2,1,4,7,6,7,8,9,0,0,0,0}
};

printf("\n%u %u %u %d", a, *a, **a, ***a);
}

// a = addressof first byte in the whole array
// *a = addressof first byte in the whole array
// **a = addressof first byte in the whole array
// ***a = integer value at the first byte in the whole array```

- xeddiex

4. xeddiex reminds me of Maxwell Smart.

5. isn't the *a means the value at zeroth address or the base adress,if it is then why is it taking th adress of the first byte and not the value and the same goes for **a?
not being able to understand that...can u just give me some example by taking some integer value in this example,suppose like the first element of the first array,that is,1..maybe i'll be able to understand better then...hope u can help!

6. Originally Posted by SlyMaelstrom
xeddiex reminds me of Maxwell Smart.
Hmm ...In what ways or, how do I remind you of Maxwell Smart?

- xeddiex

7. Originally Posted by galmca
isn't the *a means the value at zeroth address or the base adress,if it is then why is it taking th adress of the first byte and not the value and the same goes for **a?
not being able to understand that...can u just give me some example by taking some integer value in this example,suppose like the first element of the first array,that is,1..maybe i'll be able to understand better then...hope u can help!
No, each time you dereference, you get the value of whatever the pointer was pointing to. If it's pointing to a pointer, you still get a memory address.
Code:
```char val, *ptr, **ptr2; // The second is a pointer to a pointer.
val = 3;
ptr = &val;
ptr2 = &ptr;  // See? Still pointing to memory addresses.

printf("%d", *ptr2);    // Returns a memory address (The value of ptr)
printf("%d", **ptr2);  // Returns 3 (The value of val)```
Now how does that pertain to your array? Consider that each dimension of the array requires a pointer to the array with one less dimension.

Code:
```arry    = &arry[][]
*arry   = &arry[]
**arry  = &arry
***arry = arry          // The value.```

8. Originally Posted by galmca
isn't the *a means the value at zeroth address or the base adress,if it is then why is it taking th adress of the first byte and not the value and the same goes for **a?
not being able to understand that...can u just give me some example by taking some integer value in this example,suppose like the first element of the first array,that is,1..maybe i'll be able to understand better then...hope u can help!
I wrote a little summary about dealing with multidimensional arrays a couple of days ago. You could probably find some usefulness in it, which can be found here (look for the post by xeddiex).

- xeddiex

Popular pages Recent additions