Other than being able to dereference a void**
, I don't understand the following:
void * foo, **bar;
foo++;//error
bar++;//no error
Why doesn't the first work but the second does? What's the difference?
Other than being able to dereference a void**
, I don't understand the following:
void * foo, **bar;
foo++;//error
bar++;//no error
Why doesn't the first work but the second does? What's the difference?
First snippet
foo++;//error
because, foo
is pointer to void
and you cannot have pointer arithmetic on void *
, size of the void
type is not defined.
Second snippet,
bar++;//no error
because, bar
is a pointer to a pointer to void
. So, arithmetic operation is permitted, as the size of a pointer to pointer type is well defined.
FWIW, don't get surprised if sometimes, void pointer arithmetic "works" without any error.