Whats the diff bt the codes the first one is not giving the right ans

int fun(Node *root)
{
static int sum = 0;
if(!root)
return 0;
if(root->right)
{
if(!root->right->left && !root->right->right)
{
sum+=root->right->data;
}
}
fun(root->left);
fun(root->right);
return sum;
}

int rightLeafSum(Node* root)
{
return fun(root);
}

void fun(Node *root, int *sum)
{
if(!root)
return;
if(root->right)
{
if(!root->right->left && !root->right->right)
{
*sum+=root->right->data;
}
}
fun(root->left,sum);
fun(root->right,sum);
}

int rightLeafSum(Node* root)
{
int sum=0;
fun(root,&sum);
return sum;
}

share both codes using ide link…