Announcements and Reminders
FunctionsWhat is a function?
Why write functions?
How to ...
Pass by value
Variables or values that are passed to functions by value are copied in stack memory. It is the copy that is used inside the function. The original variable in the calling function is unchanged by the function.
Pass by Reference
A reference variable is an alias for another variable, defined elsewhere in the program. Reference variables are commonly used for function arguments or return values. The use of reference variables as function argument avoids the requirement to pass a variable's address to a function and avoid the necessity to dereference variable addresses.
Reference to const
A reference to a const is used as a function argument to disallow the function from changing the argument value.
return by value
How do you use the function return?
Do you have to use the function return?
The answer is "no", but make sure you have a good reason not to.
A default argument is a value that is automatically passed as a function argument when the argument is not provided by the function call.
Why is this an error?
A function that is prototyped like this,
void funk(int x = 2, int y = 4, int z = 6);
may be called in 4 different ways: