Please explain the code given by one of the ta

void replaceSum(node *root, int *sum)
{
// Base Case
if (root == NULL) return;

// Recur for right subtree 
replaceSum(root->right, sum); 

// Now *sum has sum of nodes in right subtree, add 
// root->data to sum and update root->data 
*sum = *sum + root->data; 
root->data = *sum; 

// Recur for left subtree 
replaceSum(root->left, sum); 

}

// A wrapper over replaceSum()
void replaceSumBST(node *root)
{
int sum = 0;
replaceSum(root, &sum);
}

Here, you are finding the sum of nodes, by considering the overall sum of right nodes, becuase the right nodes will always be greater than root node, as property of BST, then that particular root data needs to be updated, thts why, we use :
*sum = *sum + root->data;
root->data = *sum;
This is so because if you carefully analyse the situation, you will understand that in question, the sum will be root->data + left_sum + right_sum;