Following is a code snippet from a code involving some transformations on a binary tree.
void fixPrevPtr(struct node *root)
{
static struct node *pre = NULL;
if (root != NULL)
{
fixPrevPtr(root->left);
root->left = pre;
pre = root;
fixPrevPtr(root->right);
}
}
Here 'pre' is initialised in every function as NULL. But when function entered 'if' clause and root->left=pre, was executed, pre that was being assigned was not NULL. It was somehow changed by the function fixPrevPtr(root->left).
My question is that how does it get changed without being even passed into the function.
Thanks in advance.