Parameters

Languages vary in both the syntax and semantics of how thy pass parameters to functions.

<aside> đź’ˇ formal parameters: defined in the function signature

actual parameters: arguments that’s passed in to the function when calling

</aside>

Parameter Passing Semantics describe how arguments are passed to functions.

Aliasing

“Aliasing” occurs when two parameters to a function unknowingly refer to the same value/object and the function modifies it.

Parameter Passing

Positional: order of the arguments must match the order of the formal parameters

Named parameters: caller explicitly specifies the name of each formal parameter for each argument

Optional parameters: provide default values for specified formal parameters. (in language without mandatory argument labels, default parameters must all be placed at the end of the parameter list)

Variadic Functions

A function that caller can pass a variable number of arguments. Different language implement this feature differently.

Return Values

Bug vs. Errors vs. Results