c++ - What is a void pointer and what is a null pointer? -
so going through interview questions came across this question
the answer question confused me throughly! seems void , null used interchangeably according question , don't believe correct. assumed void return type , null value. code-rookie , not sure know right. hence gurus out there.. if shed light extremely beneficial! :)
please express views null pointer , void pointer is. not looking difference between null , void. please verify answer of question , tell me if correct... thanks
the 2 concepts orthogonal:
- a void pointer, (
void *
) raw pointer memory location. - a null pointer special pointer doesn't point anything, definition. can pointer type, void or otherwise.
a void pointer can null or not:
void *void_ptr1 = null; void *void_ptr2 = malloc(42); void *void_ptr3 = new foo; // void * can point void *void_ptr4 = (char*)void_ptr3 + 1; // somewhere inside object
a non-void pointer can null or not:
foo *f = null; foo *g = new foo;
Comments
Post a Comment