int main()
{
int a;
void *p;
p = &a;
printf("%ld\n",(long)p);
p = p+1;
printf("%ld\n",(long)p);
}
In this program, p+1
is just incrementing the value of p by 1. I know void pointer arithmetic
is not possible in C
, so GCC
is doing it implicitly. And if yes, then is it taking it as char pointer
. Also, why dereferencing
is not possible for void pointer, if it is implicitly doing pointer arithmetic.
C does not allow pointer arithmetic with
void *
pointer type.GNU C allows it by considering the size of
void
is1
.From 6.23 Arithmetic on void- and Function-Pointers:
http://gcc.gnu.org/onlinedocs/gcc/Pointer-Arith.html
Now to answer this question:
GNU C allows pointer arithmetic with
void *
but still does not allow an object of typevoid
to be declared.