Pass by Value

If the argument within the parentheses of a function call is a variable, constant (or some other expression) it means that it is first evaluated and a COPY is then passed to the function as its input.

 

The function uses the copy of the passed in argument, and executes any statements upon that copy locally within the function.

 

Once the execution within the function is complete, control returns to the point of which the call was made, and any locally changed data within the called function is lost.

Compile & run:

1st value of myVar in main: 42
1st value of myVar in function: 42
2nd value of myVar in function: 17
2nd value of myVar in main: 42

Leave a Reply