[cs13001] Programmer-defined function question
Mikhail Nesterenko
mikhail at cs.kent.edu
Tue Sep 23 00:25:58 EDT 2014
> I have a question about return statements for programmer-defined
> functions. Is there a change in syntax or a particular statement needed
> for a function that isn't returning a value? I started work on
> Lab5_Figures, defining each function taking a parameter, and without a
> return statement. But, whenever I try to build the solution the compiler
> keeps telling me that there is an error because the functions must return a
> value. If I add a return statement to the end of the functions (even if it
> just returns the original value given to the parameter), the program
> compiles without error and the solution functions as desired. The
> instructions for the lab say to make a void-function but I can't figure out
> how.
We did not have time to cover it on Monday. The information is in
Lecture 10, slide 3.
A void function does not return a value and can only be invoked as a
standalone statement. The return value type is stated as void:
void myfunc()
in both function definition and function prototype. The definition may
or may not contain a return-statement. If return statement is there,
it cannot contain a value.
Thanks,
--
Mikhail
More information about the cs13001
mailing list