Answer to Question #57103 in C++ for priyam
void Location(int &X,int Y=4)
Need a fast expert's response?Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Next step, PX = 10 is passed by reference and PY by value. It means, only PX can change outside Location, PY will remain the same, 10. Changes of PX you can follow as described above.
Variables, passed by value does not change outside the function, because function works with their copy. Variables, passed by reference will change, because actually function works with the pointer to the original variable.
First you call Location(PY) which means you pass PY by reference. Thus, it takes PY = 2 and uses it as X variable. Inside Location, it increases value of Y: Y := Y + 2 ( = 6) and adds it to the current value of X ( = 2) obtaining 10. But X is the same as PY. Thus, PY becomes 10.
Function "Location" has two arguments, X passed by reference and Y passed by value. Moreover, Y has default value 4.
Could u explain ques#57103