Null Pointers

What is the use of null pointers?

Questions by varsha_vn

Showing Answers 1 - 6 of 6 Answers

sriranga.ch

  • Aug 31st, 2009
 

Usually in C. If are nor initialized any thing automatically some garbage information will be palced in variable. In pointers also same if we are not initialized with any variable address it will point to some memory. Avoid accessing of some other memory initialized with Null.

  Was this answer useful?  Yes

A null pointer represents a well-defined "nowhere", and is guaranteed to compare unequal to any other object or function pointer value.  It's often used as a sentinel value to indicate the failure of an operation (such as from malloc() or fopen()) or end of input (such as from fgets()). 

Pointer variables that aren't currently pointing to anything valid should be set to NULL.  This helps avoid problems with "dangling" or "wild" pointers, which contain values that don't correspond to active objects in memory.  Attempting to dereference an invalid pointer (including NULL) invokes undefined behavior. 

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions