| Start |
|---|
| Call by value Upon calling a function there are new elements created on the program stack. These include some information about the function and also space (memory locations) for the parameters and the return value. When handing over a parameter to a function the value of the used variable (or literal) is copied into the memory location of the function parameter. This implies that now there a two memory locations with the same value. Inside of the function we only work on the parameter memory location. After leaving the function the memory on the program stack is popped (removed) which erases all data of the function call, including the memory location of the parameters we used inside. Thus, the values changed inside the function do not affect the outside variables values. In this code we create variables inside the main function. These get assigned values. Upon calling the functions there are two new variables created: The following graphic symbolizes what is happening on the stack and why there is no change in varibale It is called "call by value" because we do not hand over the variables but only the values of these variables. |
Read Article
https://develop.horje.com/learn/1434/reference