Segm fault and return statement

and i dont understand this line ,
return max(ls,max(rs,0)+root->data);

hi @premang the code is not giving any segmentation fault and running fine and giving output as well.

1 Like

i dont understand this line ,
return max(ls,max(rs,0)+root->data);

i dont think my code is giving correct o/p

@premang
This line is actually like this.
return max(ls,max(rs,0))+root->data;
max(ls,max(rs,0)) this part will consider the max from ls, rs and 0, and we add it to root->data and return it.

with this i/p = 10 2 20 -1 -1 1 -1 -1 10 -1 -25 3 -1 -1 4 -1 -1
i am getting o/p = 32 in the video sir is getting o/p = 42

hi @premang in the end, your answer is stored in the variable “global_max” but you are printing the answer returned by the function. Do the function calls like this
image

1 Like

thank you, it;s working now

1 Like