bluemoon wrote:
sortie wrote:
Curiously, *(ptr + index) is the same as *(index + ptr) which through the first rule is the same as index[ptr].
No, you need to consider data type in question too (which is crucial to produce final memory address), *(ptr + index) uses
ptr as current data type, while *(index + ptr) uses
index.
No, since index is size_t or ssize_t compatible type, the dereference would not work if it was used as the base type in such expression.
It's easy to illustrate with the simple code snippet:
Code:
#include <stdio.h>
#include <stdint.h>
int main()
{
uint64_t arr[]={1,2,3};
uint32_t agg[]={5,6,7};
printf("%llu\n", *(arr+1)); // 2
printf("%llu\n", *(1+arr)); // 2, not 0x0200 0000 0000 0000
printf("%u\n", *(agg+2)); // 7
printf("%u\n", *(2+agg)); // 7, not 0x0006 0000
}