Write out your answers for these questions on a separate piece of paper.
Question #1: A(n) ____________ parameter receives a copy of the corresponding argument; a(n) ____________ parameter receives a reference to the corresponding argument.
Question #2:
An ampersand &
is used to designate a(n) ____________
parameter.
Question #3: The ____________ of a particular variable is the section of code where that variable is defined.
Question #4: ____________ scope is limited by the curly braces of a compound statement.
Question #5: ____________ scope extends all the way to the end of the source file.
Code #1:
Write a prototype for the function foo()
that has a return
type of void
, an int
value parameter frodo
,
and an int
reference parameter samwise
.
Code #2:
Write a function stub for the function foo()
as described in
the previous question.
Code #3:
Write a declaration for a string
variable named gandalf
as a local variable. Indicate the context of the
declaration to demonstrate that it is, in fact, a local variable.
Code #4:
Write a declaration for a string
variable named balrog
as a non-local variable (visible through most of the
code file). Indicate the context of the declaration to demonstrate
that it is, in fact, an extern variable.
Code #5:
Write a declaration for a string
variable named int
. Why won't the C++ compiler like this?