Originally posted by: glugglug
Originally posted by: arcain
And...
*(3 + p) is equivalent to *(p + 3)...
which means 3[a] is equivalent to a[3].
I doubt that very much, might have to try it.....
*(p+3) figures out that p is an int * and actually adds 3 * sizeof(int) = 12 before dereferencing.
3[a] shouldn't work for several reasons:
1. The compiler will complain that "3" is not a pointer type
2. Even if it treated 3 as a void*, adding the value of "a" as an int wouldn't work unless your array elements are 1 byte each.
You should give it try..
Here, with non-bytesized elements:
#include <stdio.h>
int main()
{
float array[4] = { 0.0, 1.0, 2.0, 3.0 };
int i;
for (i = 0; i < 4; i++) {
printf("i = %d, array[ i ] = %e\n", i, array[ i ]);
printf("i = %d, i[array] = %e\n", i, i[array]);
}
printf("0[array] = %e\n", 0[array]);
printf("1[array] = %e\n", 1[array]);
printf("2[array] = %e\n", 2[array]);
printf("3[array] = %e\n", 3[array]);
return 0;
}