c - pointer changes value without being passed as argument -


following code snippet code involving transformations on 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' initialised in every function null. when function entered 'if' clause , root->left=pre, executed, pre being assigned not null. somehow changed function fixprevptr(root->left).

my question how changed without being passed function.

thanks in advance.

pre static keeps it's value call call. fixprevptr() recursive (calls itself) change pre "sticks".


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -