A function,depending on whether arguments are present or not whether a value is returned or not,may belong to one of the following categories.
category 1: Functions with no arguments and no return values.
category 2: Functions with arguments and no return value.
category 3: Functions with arguments and one return value.
category 4: Functions with no arguments but returns value.
category 5: Functions that return multiple values.
Functions with no arguments and no return values:
when a function has no arguments,it does not receive any data from the calling function.similarly,when it does not return a value,the calling function does not receive any data from the called function.In effect,there is no data transfer between the calling function and the called function.This is depicted in fig.1.The dotted lines indicate that there is only a transfer of control but not data.
As pointed out earlier, a function that does not return any value cannot be used in an expression.It can only be used as an independent statement.
It is important to note that the function value receives its data directly from the terminal.The input data include principle amount,interest rate and the period for which the final value is to be calculated.
Functions with arguments and no return value:
the main function has no control over the way functions receive input data.for example,the function printline will print the same line each time is called.same is the case with the function value,we could make the calling function to read data from the terminal and pass it on to the called function.This approach seems to be wiser because the calling function can check for the validity of data,if necessary,before it is handed over to the called function.
The nature of data communication between the calling function and the function with arguments but no return value shown in fig.
Functions with arguments and one return value:
No comments:
Post a Comment