Ch_6_Functions Flashcards
Modular Programming
Breaking a program into a set of manageable functions for modules. Sometimes called Divide and Conquer.
Function
A collection of statements that performs a specific task.
Function Call
A statement that causes a function to execute.
Function Definition
The statements that make up the function.
The parts of every Function definition.
- Name
- Parameter List
- Body
- Return Type
Note: The Function Header includes the Return Type, Name, and Parameter List
Void Functions
Functions that do not return a value.
Function Prototype
Eliminates the need to place a function definition before all calls to the function.
Arguments
Values sent into a function by the program.
Parameter
A special variable that holds a value being passed as an argument into a function.
The parameters of a function are local variables. Their scope is limited to the body of the function.
Value Returning Functions
Functions that return a value
Local Variable
Variables defined inside of a function that are local to that function. They are hidden from statements in other functions, which normally cannot access them.
Not automatically initialized, as global variables are.
Global Variable
Any variable defined outside of all the functions in the program, including main.
Automatically initialized to zero.
Global Constant
A constant variable available to every function in the program.
Static Local Variables
Are not destroyed when the function returns.
Default Arguments
Are passed to parameters automatically if no argument is provided in the function call.
Notes:
- The value of a default argument must be a literal value or a named constant.
- When an argument is left out of a function call (because it has a default value), all the arguments that come after it must also be left out.
- When a function has a mixture of parameters both with and without default arguments, the parameters with default arguments must be last.
Reference Variable
A variable that references the memory location of another variable. Any change made to the reference.
An ampersand must be used in the prototype and header.
The reference must be made to a variable, and not literal, constant, or expression.
Three common instances when reference parameters are used.
- When data values being input in a function need to be known by the calling function.
- When a function must change existing values in the calling function.
- When a file stream object is passed to a function.
Overload Functions
Functions that have the same name but different parameter lists.
Function Signature
The name of the function and the data types of the function’s parameters in the proper order.
Exit Function exit()
Causes a program to terminate, regardless of which function or control mechanism is executing.
The cstdlib header file is required
EXIT_SUCCESS
A named constant used with the exit() function to indicate a successful program termination.
EXIT_FAILURE
A named constant used with the exit() function to indicate a problem has occurred.
Stub
A dummy function that is called instead of the actual function it represents. It usually displays a test message acknowledging that it was called, nothing more.
Driver
A program that tests a function by simply calling it.