C 語言最大難點揭秘[3]
發表于:2008-04-25來源:作者:點擊數:
標簽:難點揭秘語言
關鍵字:c++懸空指針
懸空指針比較棘手。當程序員在內存資源釋放后使用資源時會發生懸空指針(請參見清單 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.kjueaiud.com