📜  垃圾收集和悬空引用 - 任何代码示例

📅  最后修改于: 2022-03-11 14:57:45.987000             🧑  作者: Mango

代码示例1
int x= 1000;   //creates a new 
memory block
int* p = x;   // *p is the pointer to address block 1000(mem location) 
int *p = 20;
printf("%d",*p); //This pointer prints 20 
delete p; 
printf("%d",*p); // This would throw an error, because now p is 
                 // inaccessible or dangling. *p is a dangling pointer.