C interview questions

Is void pointer arithmetic a valid one? Why?

102. Is void pointer arithmetic a valid one? Why?

Arithmetic operation on void pointer is not valid one. Void pointer is a generic pointer. It is not referring int, char or any other data type specifically. So, we need to cast void pointer to specific type before applying arithmetic operations.

Note:

Pointer arithmetic itself is not valid one. Pointer addition, multiplication and division are not allowed as these are not making any sense in pointer arithmetic.

But, two pointers can be subtracted to know how many elements are available between these two pointers.