懸空指針比較棘手。當程序員在內存資源釋放后使用資源時會發生懸空指針(請參見清單 5):
清單 5. 懸空指針
void f8()
{
struct x *xp;
xp = (struct x *) malloc(sizeof (struct x));
xp.q = 13;
...
free(xp);
...
/* Problem! There's no guarantee that
the memory block to which xp points
hasn't been overwritten. */
return xp.q;
原文轉自:http://www.anti-gravitydesign.com