Chapter 6: Functions
_____ arguments are passed to parameters automatically if no argument is provided in the function call.
Default
T/F All static variables are initialized to -1 by default.
False
T/F Function headers are terminated with a semicolon.
False
How would a static local variable be useful?
It would enable a function to retain a value between function calls. For example, it can keep track of the number of times the function has been called.
T/F Static local variables are not destroyed when a function returns.
True
T/F The scope of the parameter is limited to the function which uses it.
True
T/F When a function with default arguments is called and an argument is left out, all arguments that come after it must be left out as well.
True
When a function accepts multiple arguments, does it matter order the arguments are passed in?
Yes. The first argument is passed into the parameter variable that appears first inside the function header's parentheses. Likewise, the second argument is passed into the second parameter, and so on.
the value of a default argument must be ___
constant
the __ function causes a program to terminate
exit ( )
If a function has a local variable with the same name as a global, which can only be seen?
local
An ___ eliminates the need to place a function definition before all calls to the function.
prototype
Reference variables allow arguments to be passed by ___
reference
When used as parameters, ___ variables allow the function to access the parameter's original argument
reference
When only a copy of an argument is passed to a function, it is said to be passed by a ___
value
If a function doesn't return a value, the word ___ will appear as it's return type
void
Unless you explicitly initialize global variables, they are auto initialized as
0
Why do local variables lose their values between calls to the function in which they are defined?
Because they are created in memory when the function begins execution, and are destroyed when the function ends.
T/F The exit function can only be called from the main.
False
T/F When a function terminates, it always branches back to the main, regardless where it was called from.
False
Where do you define parameter variables?
Inside the parentheses of a function header.
T/F A stub is a dummy function that is called instead of the actual function it represents.
True
Either a function's ___ or its ___ must precede all calls to the function
definition, prototype
Two or more functions may have the same name, as long as their ___ are different
parameter lists
Special arguments that hold copies of function arguments are called
parameters
_______ local variables retain their value between function calls
Static
References are defined like regular variables except there is an ___ in front of the name
&
What is the difference between an argument and a parameter variable?
An argument is a value passed to a function. A parameter variable is a variable local to the function which receives the argument. That is to say, the argument's value is copied into the parameter variable.
T/F Changes to a function parameter always affect the original argument as well.
False
T/F It is not possible for a function to have some parameters with default arguments and some without.
False
If you are writing a function that accepts an argument and you want to make sure the function cannot change the value of the argument, what do you do?
If the argument is passed by value, nothing needs to be done. The function cannot access the argument. If the argument is passed by reference, the parameter should be defined with the const key word.
What is the advantage of breaking your application's code into several small procedures?
It makes the program easier to manage. Real-world programs can easily have thousands of lines of code, and unless they are modularized, they can be very difficult to modify and maintain.
T/F Arguments are passed to the function parameters in the order they appear in the function call.
True
T/F Function prototypes are terminated with a semicolon.
True
T/F Functions should be given names that reflect their purpose.
True
T/F If other functions are defined before the main, the program still starts executing at the main function.
True
T/F In a function prototype, the names of the parameter variables may be left out.
True
T/F Initialization of static local variables only happen once, regardless of how many times the function in which they are defined is called.
True
T/F Many functions may have local variables with the same name.
True
T/F Overuse of global variables can lead to problems.
True
When only a copy of an argument is passed to a function, it is said to be passed by ______
Value
Values that are sent into a function are called
arguments
___ variables are defined outside of a function, are accessible to any function within their scope, and provide an easy way to share large amounts of data among all the functions in a program
global
The ___ is the part of a function definition that shows the function's name, return type, and parameter list
header
When a function uses a mixture of parameters with and without default arguments, the parameters with default arguments must be defined ____
last
the ___ statement causes the function to end immediately
return (or return x)