Here are the answers:
x[0][0] ➜ *(x[0]+0) ➜ *(*(x+0)+0)
x[0][1] ➜ *(x[0]+1) ➜ *(*(x+0)+1)
x[1][0] ➜ *(x[1]+0) ➜ *(*(x+1)+0)
x[1][1] ➜ *(x[1]+1) ➜ *(*(x+1)+1)
Explanation:
Fetching/Echoing a value from inside an addrress uses the dereference pointer *
and should follow the address where the values would come from.
Let's take x[1][0]
as an example:
- We are fetching the address of
x[1]
+ an offset value, or how far we would move from the current address, our offset is 0
and thus the address of x[1][0]
using pointer is x[1]+0
And to fetch the value would would add the *
operator to call for the value inside the address and now we have *(x[1]+0)
But we still fetch the first address x[1]
using square bracket []
operator, so using pointers...
- We would fetch
x[1][0]
using pointers by moving from offset to offset, the only thing we need to do now is to convert x[1]
inside *(x[1]+0)
so it would be *(*(x+1)+0)
See it working, Click Here
The same process happens on multidimensional arrays
Also... You can simply the equation whenever posssible
Can be simplified : *(*(x+0)+0)
➜ *x
,
*(*(x+1)+0)
➜ *(x+1)
*(*(x+0)+1)
, ➜ *(*x+1)
Cannot be simplified : *(*(x+1)+1)
Reasons why? As have mentioned we are moving from one offset to another and we're not adding the offset all together
*(*(x+0)+0)
Obviously, did not move an offset so it could be simple as *x
*(*(x+1)+0)
This offset on the inner address have moved *(x+1)
but the outer did not +0
so it could be *(x+1)
itself
*(*(x+0)+1)
This offset on the inner address did not moved x+0
but the outer have moved +1
so it could call the *(x+0)
to be *x
thus making it *(*x+1)
*(*(x+1)+1)
This one cannot be simplified anymore 'cause we need to move 1 offset on the inner pointer call and move 1 offset again afterwards.