Functions and Headers Flashcards
arguments, return values, and function prototypes are all parts of a blank
function
multiple source files, the C preprocessor, include guards all require blank
headers
blank are named units of code that can be called upon to perform a task
functions
examples of functions include
getline( ) swap( ) strlen( ) pow( ) replace ( ) sort ( ) toupper( )
sometimes functions are called from an object such as .size( ) from a vector or string
these are member functions also called
methods some other methods are .begin( ) .end( ) .open( ) .close( ) .second( ) .first( )
to call a function, we supply it with the information that it needs, called blank
arguments
for example, pow( ) needs two arguments: base and exponent
blank supplied by listing them in order, separated by commas, in the parentheses after the function’s name
arguments
functions have the following general form
return_type function_name(argument_type 1 argument_name 1, ...) { //code body; }
the blank is any valid data type such as int or string
return type
the function’s blank follows the same rules as variable’s blank
name(s)
the blank is a comma-separated list of type and variable names
arguments list
a blank is a value handed back from a function to be used where the function was called
return value
a function call is effectively replaced by its blank
return value
cout «_space;repeat_string(“Hello! “,5);
What does this mean?
cout «_space;“Hello! Hello! Hello! Hello! Hello! “;
functions make code blank
reusable
more organized
more readable