Problems with Pointers


1. Problems with Pointers

Nothing will get you into more trouble than a "wild" pointer! Pointers are a mixed blessing. They give you tremendous power and are useful for a number of different operations. But, when a pointer accidentally contains the wrong value, it can be the most difficult bug to track down. Bugs caused by bad pointers are hard to find because often the pointer itself does not exhibit the problem. Instead, the problem shows itself only indirectly, perhaps several steps after you have performed a pointer operation. For example, if a pointer accidentally points to the wrong data, then a pointer operation may alter this data, but the problem associated with this unintended alteration will not manifest itself until later in the program’s execution. This may lead you to look for the bug in the wrong place. By the time the problem is evident, there may be little or no indication that the pointer was the original cause of the problem. For this reason, pointer bugs have caused programmers to lose sleep time and time again. Since pointer problems are so troublesome, let’s look at some ways they can happen, and how they can be avoided.
Share on Google Plus