CPP - Pass by Reference Using Pointers

what if the function returns the answer? in that case the varianble in main will change ?

In case of pass by reference, even if the function returns an ans,if you print that answer in main, changes will be reflected back in the main, because in passing by reference you are working on the original value, instead of a copy. Thus changes will be reflected in the main.

What about in pass by value?

In case of pass by value, when the function returns an ans, if you print that ans in main, changes will not be reflected in the original values in the main, because in passing by value, you are working on the copy. Thus original values remain same.