Chapter 6 - Functions Flashcards
Define: Code reuse
Write the code to perform a task ONCE, then reuse it each time you need to perform the task.
Define: Function call
A statement that causes a function to execute.
Define: Function Definition
Contains the statements that make up the function.
All function definitions have what 4 parts?
1) Return Type
2) Name
3) Parameter list
4) Body
Define: Return type (of a function)
#1 data type of the value that is sent FROM the function listed first int main() --> int is the RETURN TYPE
Define: Name (of a function)
#2 Should give each function a descriptive name - in general, same rules apply as to variables for naming int main() --> main is the NAME
Define: Parameter List (of a function)
#3 List of variables that hold the values being passed TO the function int main() --> () is the parameter list (it's empty!)
Define: Body (of a function)
The set of statements that perform the function's operation. enclosed in a set of braces int main() { BODY HERE }
Define: Function Header
The line in the definition that reads int main() (the first line)
Define: Void functions (they return….)
Some function simply perform one or more statements and then terminate, without returning a value. these are VOID functions. Example: void displayMessage() { cout << "hello from the function displayMessage. \n"; }
Notice: not return statement
void displayMessage() { cout << "hello from the function displayMessage. \n"; } What part is the function header? How would you "call" this function?
Function Header: void displayMessage()
Call: displayMessage();
Fuction prototypes are also known as …
Function declarations
You must place either the function definition or the function prototype _______ all calls to the functions.
What happens if you don’t?
BEFORE
Or else the program will not compile
What would a “function prototype” for the following function definition be? What’s different about it?
void displayMessage() { cout << "hello from the function displayMessage. \n"; }
void displayMessage(); - semicolon at the end
Tells compiler the function displayMessage has a void return type (doesn’t return a value) and uses no parameters.
When a function is called, the program may send _____ into the function.
VALUES