Why cant I perform arithmetic on a void pointer?

Q

Why cant I perform arithmetic on a void pointer?

✍: Guest

A

The compiler doesn't know the size of the pointed-to objects. (Remember that pointer arithmetic is always in terms of the pointed-to size; Therefore, arithmetic on void *'s is disallowed (though some compilers allow it as an extension). Before performing arithmetic, convert the pointer either to char * or to the pointer type you're trying to manipulate

2015-12-07, 745👍, 0💬