7. Functions Flashcards
What is a function?
A block of code that can be called by other statements.
Describe the parts that can be used when defining a function
Return type,
Function name,
( ) containing zero or more parameters (return type plus parameter name) separated by commas, and
{ } containing one or more statements for the body of the function, and optionally a return type.
How do you call or invoke a function?
Code the name of the function and a set of parentheses.
Within the parentheses, code one or more arguments in the same order as the parameters in the function definition.
What does the void return type mean?
The function does not return any data.
What is the relation between the return type and the return statement?
The return statement must return data of the return type.
Identify best practice for naming functions
Start the name with a verb,
can follow verb with a noun or adjective plus a noun,
name should reasonably describe purpose of function.
Identify best practice for naming functions
Start the name with a verb,
can follow verb with a noun or adjective plus a noun,
name should reasonably describe purpose of function.
How do you declare a function without its definition?
Code the function’s return type, name, and optionally the parameters, followed by a semicolon.
Though optional, including the parameters improve readability of the code.
What do you call a function that has been declared but not defined?
function prototype
What is a local variable?
A variable defined inside a function.
What is a global variable?
A variable defined outside of all functions.
Where can a local variable be used?
Only within the function that defines it.
What is a shadow variable?
When a local variable has the same name as a global variable.
What happens to variable operations if you have a shadow variable?
In a function that defines the variable, all operations are done on the local variable.
Otherwise, all operations are done on the global variable.