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:

  1. a void pointer, (void *) raw pointer memory location.
  2. 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

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -