Take the 2-minute tour ×

I am getting "Unhandled exception at 0x00263ACB in Trees.exe: 0xC0000005: Access violation reading location 0x00000000." on the first if statement of remove_node function. Can anyone give me a suggestion, I am stumped.


share|improve this question
Looks like node_ptr isn't initialized. Can you post the code where it supposedly gets initialized? –  juanchopanza Sep 25 '12 at 5:23
First, improve your accept rate. Second, is node_ptr a nullptr? Use a debugger to inspect the values and call stack to make sure you're doing things right. –  Cornstalks Sep 25 '12 at 5:23

1 Answer 1

up vote 0 down vote accepted

It looks like the error could be hidden here: In both cases you go to the left child and at some point approach a leaf (and try to delete its child which doesn't exist). Try to replace one of remove_node(num, node_ptr->left); by remove_node(num, node_ptr->right);

Also it's a good idea to first check whether a node exists.

share|improve this answer
My apologies, I was confused that the error was coming from code further up the line. When I did modified the code where you suggested the error discontinued. Thank you very much! –  JonDog Sep 25 '12 at 22:17

Your Answer


