C Interview Questions and Answers


Is NULL valid for pointers to functions?

Yes There is no ``total generic pointer type.''

void *'s are only guaranteed to hold object (i.e. data) pointers; it is not
portable to convert a function pointer to type void *. (On some machines, function
addresses can be very large, bigger than any data pointers.)

It is guaranteed, however, that all function pointers can be interconverted, as
long as they are converted back to an appropriate type before calling. Therefore,
you can pick any function type (usually int (*)() or void (*)(), that is, pointer
to function of unspecified arguments returning int or void) as a generic function
pointer. When you need a place to hold object and function pointers interchangeably,
the portable solution is to use a union of a void * and a generic function pointer
(of whichever type you choose).

Posted by:Richards