Edit: The similar question asked before has not addressed some perspectives related to the issue.
In the ANSI C book by Kernighan and Ritchie, they say that the following are equivalent
a[i]
*(a+i)
I don't see how this can be true for elements that occupy more than one address space, e.g. structs.
Please explain? Edit: Thank you for all answers, but I don't quite understand it. It would seem I am suffering the same confusion as @CucumisSativus from his answer and comments to it.
Say sizeof(*a) is 3. If for some reason I wanted to access the middle byte of the first element in a, I had thought this is how I would do it: *(a+1)
.
Say the address of a
is 10, and the sizeof each element is 20. And say we want to get the pointer to the second element. As I see it, we could do this: p = (10 + 20). I thought this would be equivalent to &a[1]
.
I'm having real trouble explaining what I don't understand!!