为什么我的指针不是NULL?

Tyl*_*aff 3 c++ null pointers

我有一个家庭链表.我删除了其中一个孩子的兄弟姐妹.

p->myWife->myChildren=p->myWife->myChildren->mySibling; //makes the sibling the child so the list is not broken when deleting
delete p->myWife->myChildren->mySibling;
Run Code Online (Sandbox Code Playgroud)

然后我打印基于此的子/兄弟属性

if(p->myWife->myChildren->mySibling!=NULL){
 print the childs attributes
}
Run Code Online (Sandbox Code Playgroud)

每当我打印时,它会为兄弟打印一个奇怪的数字(我假设它的内存地址)我需要做什么才能使该指针为空?

Aat*_*man 10

删除指针不会将其设置为零.它只是释放指针指向的内存.要将其设置为NULL,您必须自己将其设置为NULL.

p->myWife->myChildren->mySibling = NULL /*defined to be zero */;
Run Code Online (Sandbox Code Playgroud)