• 0

C language


Question

4 answers to this question

Recommended Posts

  • 0
Dangling pointer...0_o

It's where the memory its address points to was freed but the program keeps on using the pointer (which is now effectively pointing to random memory) anyway.

The answer is to stop using it at that point, or at the very least set the pointer to NULL once the associated memory has been freed.

Link to comment
Share on other sites

  • 0
It's where the memory its address points to was freed but the program keeps on using the pointer (which is now effectively pointing to random memory) anyway.

The answer is to stop using it at that point, or at the very least set the pointer to NULL once the associated memory has been freed.

Yeah it's ablosutely more safe to set it to NULL, nothing REALLY bad can come out from accessing a NULL pointer, you will understand your mistake right away. If however at some point later on you re-use that pointer which used to point to useful memory for your program, your program may continue to work but it may end up giving you false results and corrupting your data.

Those memory problems are very sneaky, I remember a program was giving segfault on my PC but it was working "fine" on my friend's PC apparently giving wrong results (and it is not always easy to check if a result is correct)

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.