[cs13001] Format of Midterm?

Mikhail Nesterenko mikhail at cs.kent.edu
Wed Oct 17 10:28:32 EDT 2012


In a void function, it is explicitly stated that, this function can
only be used as a standalone statement. The compiler will check the
syntax and ensure that it is never used inside the expression and that
the return statement of this function does not contain the expression.

A function that returns a value may be used in an expression or as a
standalone statement. In the latter case the return value is
discarded. However, the compiler cannot assist with these
functions. Although legal, using non-void functions as standalone
statements is considered bad style.

Thanks,
--
Mikhail


> One other question Professor,
> What is the point in using a void function when using an int function is
> virtually the same?
> 
> void showNum (int& number) {
> cout << number << endl;
> number++;
> cout << number << endl;
> 
> return;
> }
> 
> int main(){
> 
> int num = 1;
> showNum (num);
> cout << num << endl;
> }
> 
> Then this is also the same.
> 
> int showNum (int number) {
> cout << number << endl;
> number++;
> cout << number << endl;
> 
> return number;
> }
> 
> int main(){
> 
> int num = 1;
> int temter = showNum (num);
> cout << temter << endl;
> }
> 
> Is a void function supposed to be more simple?


More information about the cs13001 mailing list