8- programmer-defined functions, local and global variables, call-by-value Flashcards
Function
named group of statements carrying out a particular task
to carry out its task the function accepts arguments
Predefined function
provided in libraries for the benefit of all programmers
Programmer-defined function
written by programmer
Caller
function that invokes another
Callee
function that is being invoked
Function definition
specifies instructions that the function executes
consists of head, body
Function prototype
declares (quickly introduces) the function
Expanded form
mentions parameter types and names: names are optional but sometimes desirable for clarity
int add1(int i);
Abbreviated form
mentions only parameter types
int add1(int);
Local variable
variable that is declared inside a function is local (to that function): it cannot be used outside of the function
the scope of such variable is from declaration till end of function
parameters are also local variables
local variables of two different functions are different even if they have the same name
variables declared in main() are local to main()
Global constant
a constant declared outside any function definition
it can be used (its scope is) anywhere in the program from the place it is declared
Global variable
variable declared outside any function definition
int errorcode = 0;
global variable scope is any function of the program from variable declaration down, functions can read and update global variable
using global variables introduces side effects to functions
what’s “side effect” gain?
makes program hard to understand: avoid!