Этот код показывает довольно много, что вы делаете:
#include<stdio.h>
int main() {
int onetwo[] = { 1, 2};
/*create a void pointer to one two*/
void* ptr = (void*) onetwo;
printf ("pointer onetwo[0] = %p\n", &onetwo[0] );
printf ("pointer onetwo[1] = %p\n", &onetwo[1] );
/* since you are doing pointer arithmetics
* it's really important you cast ptr back to
* int* otherwise the compiler might not
* return a pointer to onetwo[1] but if sizeof(int)
* is 4 bytes
*/
printf ("value = %d\n", *((int*)ptr + 1));
/* in this print statement ptr is still a void* when
* it is incremented, therefore it points between
* onetwo[0] and onetwo[1]
*/
printf ("value = %d\n", * ((int*)(ptr + 1)));
/*casting to int* is for illustration properties */
printf ("This points between onetwo[0] and onetwo[1] because it's at %p\n", (int*) (ptr + 1));
return 0;
}
выход на моих выходах машины:
~/programming/stackoverflow$ ./p
pointer onetwo[0] = 0x7fffdd8e2fc0
pointer onetwo[1] = 0x7fffdd8e2fc4
value = 2
value = 33554432
This points between onetwo[0] and onetwo[1] because it's at 0x7fffdd8e2fc1
Я надеюсь, что это демонстрирует некоторые из эффектов указателя арифметики.
Проверьте ссылку [операторский приоритет] (http://en.cppreference.com/w/c/language/operator_precedence). –