3

I have a linked list of families. I delete one of the childs siblings like so.

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 later i print the child/siblings attributes based upon this

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

Whenever I print though, it prints a weird number for the sibling (im assuming its a memory address) What do I need to do to make that pointer null?

1

3 Answers 3

10

Deleting a pointer doesn't set it to zero. It just deallocates the memory being pointed to by the pointer. To set it to NULL you will have to set it to NULL yourself.

p->myWife->myChildren->mySibling = NULL /*defined to be zero */; 
Sign up to request clarification or add additional context in comments.

Comments

3

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

p->myWife->myChildren->mySibling = NULL; 

Comments

2

After deleting, set the pointer as NULL

p->myWife->myChildren->mySibling = NULL; 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.