function func_name(params)
: ret_type ;
begin
...
end
In this notation,
and
encloses a section that is optional. This
means the formal parameters are optional.
It is important that the programmer remember to assign a returned value to the name of a function. The Pascal compiler does not check and make sure a function always returns a value! In other words, the following function is perfectly correct:
function useless : integer;
begin
writeln('I am useless.')
end;
What do you think the following code prints?
writeln(useless);
Because the function definition of useless does not specify any particular value to return (as an assignment to useless), its actual returned value is undetermined. This means there is a value returned every time useless is called, it's just that we can not determine what that value is. This is not to say that useless returns a random value because the value returned by useless does depend on the useage of useless and other factors in the program.