I am in week 5(data structures) and I tried to make a simple binary search tree. then I tried to create a function for getting around on this tree! this is a part of get_around function :
printf("tree->number = %i\ntree->right = %p\ntree->left = %p\n" , tree->number ,tree-
>right,tree->left) ;
printf("In which way do yo want to continue(right = r , left = l ,end = any character) ?\n") ;
printf("&tree->right1= %p\n",&tree->right) ;
char way ;
scanf("%s" , &way) ;
printf("&tree->right2=%p\n",&tree->right) ;
if(way == 'r' && tree->right != NULL)
{
get_around(tree->right) ;
}
there are two "printf" before and after "scanf" and they should print the same thing , but they print different addresses ! when I omit scanf , address doesn't change at all and function works !!! Why my allocated memory (tree->right) should change after "scanf" ?
printf
statements above. The first saysprintf("&tree->right1
and the second saysprintf("&tree->right2
. Is that how it is in your actual code? Because right now, you appear to be referencing two different things.