> But *(pi+3) would give *(22ff10 + 3) = *(22ff13) which still would be 31 and not 12.
No, it is not.
Here's a nice little table,
Code:
----------------------------
x | 0 | 1 | 2 | 3 | 4 |
*(pi + x) | 30 | -1 | 3 | 12 | 100 |
-----------------------------
Ignore the addresses, they're meaningless for this explanation.
Of course,
Code:
*(pi + 0) = num[0] = 30
*(pi + 1) = num[1] = -1
*(pi + 2) = num[2] = 3
*(pi + 3) = num[3] = 12
*(pi + 4) = num[4] = 100
So, using the magic table. *(pi + 3) == num[0 + 3] = 12
Where do you get the 31 from?!
Don't forget about operator precedence, "pi" is an address to the first element in num[]. Note:
address.. The rules in C of precendence state, in this case, evaluate what's ever in the brackets then dereference this value as an address. That is, *(p + x) means, add p to x and call this "temp", and then dereference "temp". And out pops your value ;)
> Surely if adding three address and then finding the value would give 33?
No, that would be 12. Finding the value at address (num[0]) then adding 3 would be 33.