Multidimensional array and pointer arithmetic

Dec 6, 2013 at 6:23pm
int a[1][1];

a[0][0] = 1;

Why must I use the deference operator twice to get the value at a[0][0] (**a).

Why isn't it just *a like it is in a non multidimensional array?

Any help would be greatly appreciated!
Dec 6, 2013 at 6:39pm
It's the simple fact that *a == a[0]. It wouldn't make sense for *a to be both a[0] and a[0][0].

In any case, the general rule is *(a+i) == a[i] so if you want a[0][0], you'll need *(*(a+0)+0) or simply **a.
Last edited on Dec 6, 2013 at 6:39pm
Dec 6, 2013 at 6:49pm
Thanks for the help!
Topic archived. No new replies allowed.