modular programming
function
motivation for modular programming
function call
statement causes a function to execute
function definition includes:
function format
int main () {
cout «_space;“Hello World\n; // function
return 0; // body
}
int = return type
main = function name
( ) = parameter list
function return type
calling a function
function prototypes
how calling a function works
what must the compiler know about a function
sending data into a function
other parameter terminology
function call format
evenOrOdd (int);
function prototype format
int evenOrOdd (int);
function header format
int evenOrOdd (int num)
when passing multiple arguments . . .
pass by value
functions can be used to . . .
higher-level functions
return statement
value-returning function
value-returning function format
double sum (double num1, double num2) {
int result = num1 + num2;
return result;
} // or return num1 + num 2;
where total = sum( value1, value2);
double sum = return type
result = value being returned
different return value methods