techpreparation-homepage

Home  Interview Questions  Certifications  Aptitude Questions  Tutorials  Placement Papers  Search  Resume  Soft Skills  Video  Forum  Blog

Android app on Google Play

Technical Interview Questions

Java Interview Questions
Unix Interview Questions
SQL Interview Questions
C# Interview Questions
                              .........More

Aptitude Interview Questions
C/C++ Aptitude Questions
C Aptitude Questions
                              .........More

Tutorials
C Tutorial
C++ Tutorial
                              .........More

Programming Source Codes
C/C++ Source Codes
C# Source Codes
                              .........More

Online Quiz
C Online Quiz
C++ Online Quiz
                              .........More

 

 
Home > C Interview Questions >

Why should we assign NULL to the elements (pointer) after freeing them ?

 This is paranoia based on long experience. After a pointer has been freed, you can no longer use the pointed-to data. The pointer is said to dangle; it doesnít point at anything useful.

If you NULL out or zero out a pointer immediately after freeing it, your program can no longer get in trouble by using that pointer. True, you might go indirect on the null pointer instead, but thatís something your debugger might be able to help you with immediately.

Also, there still might be copies of the pointer that refer to the memory that has been deallocated; thatís the nature of C. Zeroing out pointers after freeing them wonít solve all problems;
 

<< Go Back to C Interview Questions. 

Have a Question ? post your questions here. It will be answered as soon as possible.

Check Object Oriented Interview Questions for more Object Oriented Interview Questions with answers

Check Data Structure Interview Questions for more data structure interview questions with answers