I’m having a tough time wrapping my head around this. Started going over 1D arrays and pointers and I understood all these things about it-
Suppose there’s
int a[]{1,2,3,4};
Here, a
is the pointer to the first element, and has its address stored in it. We can assign a pointer like so
int* p = a
and access the elements with *p
, *(p+1)
, *(p+2)
, etc…
Now with a 2D array, let’s say
int b[2][3]{1,2,3,4,5,6}
b
is still the address of the first element b[0][0]
, b[0]
and b[1]
hold addresses to the corresponding 1D arrays inside b, I can do
int* p0 = b[0]
int* p1 = b[1]
so why isn’t b an array of pointers? Why can I not do
int** p = b
And stemming from the same doubt, why will this(see attached image) not work? Why does the parameter m[][] not receive the address of m[0][0], and why does m[i][j] not navigate to the expected address?
I’ve tried googling, and watched a couple of youtube videos but nothing helps with this doubt. I would really like to have a clear understanding of what’s going on here. Thanks!
AbyssH is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.