Académique Documents
Professionnel Documents
Culture Documents
FUNCTIONS
- are subroutines containing a statement or collection of statements that perform a
certain task.
FORMAT STRUCTURE:
Function_name ( )
{ statement1;
Statement2;
statementN;
}
FUNCTION TYPE:
GENERAL SYNTAX is function_name needed only when that function is defined
after main ( ).
This is done so that the compiler can ascertain that such function exist.
PASSING BY VALUE done successively in such a way that the value of the first
identifier being sent is stored in the first receiving variable; the value of the next
identifier being sent is stored in the second receiving variable, and so on.
ARGUMENTS the called function must then be able to receive the values of the
actual parameters passed to it by individually declaring these values.
returned_type function_name ( var1, var2,varN)
RETURN causes an instant exit from the function being called and eventually
causes program execution to return to the calling function.
return ( value );
return ( expression );
VOID is used instead of any particular data type. if the called function is not to
receive any value, void can be written inside the parentheses in the function header
line , or merely nothing at all.
Void function_name ( void )
Void function_name ( )
Void function_name ( int y )
Int function_name (void)
Int function_name ( )
2 FORMS OF PPASSING PARAMETERS
1. Passing by value - it gives a copy of the value of such argument to be called
function, when the called function is executed, the values passed to it can be
changed without affecting the original values of the variables in the calling function.