Announcements and Reminders
|
||
Comments on Exercise 1As of 6:15 am this morning -49 students enrolled 41 Exercise 1 received 24 students received 5 points 17 students received 3 or 4 points Common errors (-1 point each) Use of C-style cast
Use of C header files Incorrect random number range Missing comments with your name, exercise 1, compiler, and OS Review TopicsFile I/O
Functions
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 type
return 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.
Do what you say you will do.
A
default argument is a value that is automatically passed as a function
argument when the argument is not provided by the function call.
Notes
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:
Videos |