Interview Questions

Why cant I perform arithmetic on a void pointer?

C Interview Questions and Answers


(Continued from previous question...)

Why cant I perform arithmetic on a void pointer?

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

(Continued on next question...)

Other Interview Questions