Segmentation fault


This code is giving segmentation fault but as soon as i repalce *sum=*sum+1 with only *sum , it is working fine. why am i not able to increment the value of sum in the function using pointers?

@pranaynigam
your code is not giving segmentation fault because of *sum = *sum+ 1 it is updating sum correctly inside function.
you are getting segmentation fault because inside if condition at line 47 of your code you are accessing root->left->data and root->right->data without checking if both root->left and root->right are not null.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.