Hi,
I'm working on saving a binary tree into file and reading it which later I learned called as serializing and deserializing of the tree. I found some codes and one of them is this:
Code:
void deserialize(BstNode *&root, FILE *fp);
Which is something I don't understand. Why would we take address of the pointer like that (*&root). Doesn't that equal to just root.
I always imagined pointer (*) and (&) addresses as level. While * increases it & decreases. So this seems like first going 1 level up and going 1 level down to me. But of course I know the basics of pointers although it seems not so good to understand this code.
My 2nd thought was *(&root) which is a pointer that points root's address instead of its value. Probably this is what that code means but still I can't understand how it works.
Here inside that function:
Code:
int val;
if ( !fscanf(fp, "%d ", &val) || val == MARKER)
return;
root = GetNewNode(val);
deSerialize(root->left, fp);
deSerialize(root->right, fp);
FYI when you change *&root with;
root (you get error),
*root (0 error or warning but function doesn't work).