Lecture 12 Flashcards
What is “passing in” a parameter?
Transferring in a value from the calling side to a function.
What 3 things should you consider when creating function names?
Descriptive, memorable, and consistent names
What is a function?
A program consisting of various instructions that can have input parameters/arguments, takes some action, and possibly returns a value and can be called.
What are parameters?
Parameters are the values that go in a function header. The functions parameters match up one-to-one with the arguments in a function call.
What are arguments?
Arguments are the values placed in parentheses when a function call is made.
What is a return value?
The value sent back to the part of the function that called the program.
What is a function header?
Everything that is needed for the function to interact with the larger program.
What is the function body?
Set of instructions for the function that you want to follow when the function is called.
*enclosed in curly braces after function header**
What are global variables?
Variables that exist throughout the entire program, including functions.
typically declared at the beginning of a program
What are local variables?
Variables that only exist within the function they are defined in.
What are the two main reasons to use functions?
- Functions offer conceptual separation of ideas/the ability to write code without worrying about details.
- Using functions allows you to avoid writing the same code over and over.
What is included in a function header?
- Return type
- Function name
- Parameter type(s) and name(s) in parentheses
What is the type for a function that does not return anything?
Void
Where should a function definition occur in a program?
Before it is called. Typically, functions are defined near the beginning of a file.
How would you exit a function with no return value?
Write the return command with no value
or
use void as the return type in the header and not use the return command. The function will end when the code ends.
E.g. return;