I was going through the passage pertaining to the access of individual elements of a 2D array using pointers.
It suggests the following mechanism to access the ith row's jth element of the 2D array arr[5][5]:
*(*(arr+i)+j)
From my cursory understanding of pointers, I am given to understand that the name of the array yields the address of the 0th element of the 0th row, and that any integral increment to the array will yield the base address of the next row. All's fine till this juncture, I suppose.
However, what I fail to understand is the relevance of the indirection (*) operator within the following snippet:
*(arr+i)
How is the indirection operator in this case relevant? Since the name of the array itself yields the base address of the 0th row, adding any integral number to it entails it to point to the base element of the next row. In that case, the following snippet yields the address of the ith row:
(arr+i)
And the addition of j warrants the pointer to point to the jth element of the said row.
However, in the following snippet:
*(arr+i)
Wouldn't the addition of the indirection operator cause it to yield the ith element of the row, as opposed to the address of the base element of the ith row?
Should not the following be the code to access the ith row's jth element?
*((arr+i)+j)
In the aforementioned case, incrementing arr i times will entail the code fragment (arr+i)
to point to the base address of the ith row, and then the addition of j will entail the address of the ith row's jth element, and then the indirection operator (*) would yield the element that the specific address holds, wouldn't it?
Is my reasoning satisfactory?