Because pointers provide access a memory location and because data and executable code exist in memory together, misuses of pointers can lead to both bizarre effects and very subtle errors.
Potential Problems with Pointers
Never write a declaration like
Always give your pointers an initial value
A memory leak occurs when all pointers to a value allocated on the heap has been lost, e.g.,
int isqrt ( int i )
{
int * work = new int ;
* work = i ;
while (( * work ) * ( * work ) > i )
- - ( * work );
return * work ;
}
Over time, memory leaks can cause programs to slow down and, eventually, crash.
Worse, a leaky program may come to take up so much of a systems memory that it interferes with the operation of other programs on the same system.
Dangling pointers refer to a pointer which was pointing at an object that has been deleted.