Pass by Value

When a parameter is passed into a function by value, the compiler takes a copy of that passed in value for ongoing use within the function and any execution upon that value is local to that function only, i.e. it does not effect the passed in value by the caller outside of the function.

 

Upon completion of the function, any changes to the copied in value are lost.

 

The passed in values do not have to use the same identifier name as those outside of the function. e.g. a and b in main() can be called x and y within the function. What matters is the order in which they're used and their type:

Compile & Run:

x and y in myFunc: 289, 1764
a and b in main: 17, 42

Leave a Reply