I don't understand what is the passing by reference? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

I don't understand what is the passing by reference?

help me please 🙂

26th Feb 2018, 3:56 PM
Lemina Med Selman
Lemina Med Selman - avatar
4 Answers
+ 3
Passing by reference is where you are not passing a copy of the value (such as "pass by value") but instead a reference to the value such as the memory address of the variable. For example, if you had a variable called age that you set to 5 and passed it to a function by value the function would work on a copy of age. On the other hand, if you passed it by reference the function would change the age variable itself rather than changing a copy.
26th Feb 2018, 4:10 PM
Lewis
Lewis - avatar
+ 2
sorry .... that was a typo.
26th Feb 2018, 7:02 PM
Farshaad Heydari
Farshaad Heydari - avatar
+ 1
Akash Pal / @ Lewis well done. @Lemina to put it in another way: if u pass a variable to someone (like a method) to process over it ..... if you pass it "by value" it means that the method only can work on a copy of the "value" that is inside the "variable" but it never will be able to change the original value inside the variable. and if you pass it "by reference" ... the method can change the value inside the variable......
26th Feb 2018, 6:59 PM
Farshaad Heydari
Farshaad Heydari - avatar