Why is my pointer NULL?

I have a linked list of families. I delete one of the brothers and sisters, such as.

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;

and then I print the child / siblings attributes based on this

if(p->myWife->myChildren->mySibling!=NULL){
 print the childs attributes
}

Whenever I type, it prints a weird number for brother (im takes its memory address) What do I need to do to make this pointer null?

+3
source share
3 answers

Deleting a pointer does not set it to zero. It just frees the memory pointed to by the pointer. To set it to NULL, you will need to set it to NULL yourself.

p->myWife->myChildren->mySibling = NULL /*defined to be zero */;
+10
source

deletion frees the memory referenced by the pointer. To make the pointer NULL, assign it NULL!

p->myWife->myChildren->mySibling = NULL;
+3
source

NULL

p->myWife->myChildren->mySibling = NULL;
+2
source

All Articles