Return type of replaceSum

In replaceSum I didn’t get how the output is correct we are using the int return type and take root as a reference pass by value, then how is going to make the change in the actual root and also when i am dry this code on
e.g :

4, root

7, 9 leaf

output :

16

7,8

7+9 = 16 , so root->data = 16 , is updated but why temp+root+data

We are using the int return type because we are returning root->data + temp, both of which are integers.
Passing by reference is the only reason why we are able to make changes at the real root, because we are passing its address.
When you call replaceSum(root)
root->data stores the left_sum and right_sum.
The temp value is used if there exists a parent.
So yes the final return is just the sum of all values in a tree.
But we are storing the value in root before that.

It’s just basic recursion ,the final value of temp+root->data is of no use in the question, but it was useful nodes other than the actual root.