c Flashcards
(49 cards)
Q: Why do local variables lose their values between calls to the function in which they are defined?
A: Because they are created when the function starts and destroyed when it ends.
Q: What is the difference between an argument and a parameter variable?
A: An argument is the value sent to a function; a parameter is the variable that receives it.
Q: Where do you define parameter variables?
A: Inside the parentheses of a function definition.
Q: If you want a function to not change the value of the argument it receives what should you do?
A: Pass it by value (not by reference) or use the const keyword if using reference.
Q: When a function accepts multiple arguments does the order matter?
A: Yes the order must match the parameters’ order in the function definition.
Q: How do you return a value from a function?
A: Use the return statement followed by the value.
Q: What is the advantage of breaking your application’s code into small procedures?
A: It makes the code easier to read reuse
Q: How would a local variable be useful?
A: It keeps data private to the function and avoids affecting other parts of the program.
Q: Give an example where passing an argument by reference would be useful.
A: Updating multiple values in a function like a function that modifies two numbers.
The _________ is the part of a function definition that shows the function name, return type, and parameter list.
function header
If a function doesn’t return a value, the word _________ will appear as its return type.
void
Either a function’s _________ or its _________ must precede all calls to the function.
prototype
Values that are sent into a function are called _________.
arguments
Special variables that hold copies of function arguments are called _________.
parameters
When only a copy of an argument is passed to a function, it is said to be passed by _________.
value
A(n) _________ eliminates the need to place a function definition before all calls to the function.
function prototype
A(n) _________ variable is defined inside a function and is not accessible outside the function.
local
_________ variables are defined outside all functions and are accessible to any function within their scope.
Global
_________ variables provide an easy way to share large amounts of data among all the functions in a program.
Global
Unless you explicitly initialize global variables, they are automatically initialized to _________.
0
If a function has a local variable with the same name as a global variable, only the _________ variable can be seen by the function.
local
_________ local variables retain their value between function calls.
Static
The _________ statement causes a function to end immediately.
return
_________ arguments are passed to parameters automatically if no argument is provided in the function call.
Default