Interview Questions

Can math operations be performed on a void pointer?

C Interview Questions and Answers


(Continued from previous question...)

Can math operations be performed on a void pointer?

No. Pointer addition and subtraction are based on advancing the pointer by a number of elements. By definition, if you have a void pointer, you don’t know what it’s pointing to, so you don’t know the size of what it’s pointing to. If you want pointer arithmetic to work on raw addresses, use character pointers.

(Continued on next question...)

Other Interview Questions