+ 1
Reference parameters in C++
What happens when we define one reference parameter in function definition and send two parameters from function call Example ~~~~~~~ void location (int &x, int y=4) { y+=2; x+=y; } int main () { int px=10, py=2; location (px); location (px,py); // my doubt is this function call. cout<<px<<py; }
6 odpowiedzi
+ 6
(py) value replaces the 2nd parameter's default value and nothing happens to (py) value because it's not being sent to the function by reference.
output:
14 2
+ 7
Your parameter will just take the value of py. Since the py is passed by value, no changes will be made to py.
+ 5
yup instead of 4, 2 is passed to the function
+ 2
then in second function call py value is replaced?!!
+ 2
yes thanks I understood the logic now thank u
+ 2
it doesnt give that output : 14 2