I thought that in gcc, void * and char * are handled the same when it comes to pointer arithmetic, i.e. void * "points" to one byte in memory, so the following code
void *p;
p = malloc(sizeof(void));
printf("%p %p\n",p,p+1);
really returns 0x984a008 0x984a009. Similarly, void ** points to a pointer, so incrementing by one really means incrementing by 4 bytes (in a 32-bit OS), i.e.
void **p;
p = (void **) malloc(sizeof(void *));
printf("%p %p\n",p,p+1);
returns 0x984a008 0x984a00c. However, the following code confuses me
void **p, *p1;
p = (void **) malloc(sizeof(void *));
p1 = (void **) p;
printf("%p %p\n",p1,p1+1);
Since he is returning again 0x984a008 0x984a009. What's going on here?
source
share