Questions about void data type

If the data type of a function is "void", does it mean there is no need to "return" at the end of the function???
correct
Yes, if control reaches the end of a fucntion. Otherwise you shall insert return. For example

1
2
3
4
5
6
7
8
9
10
void function( int x )
{
   if ( x < 10 )
   {
      std::cout << "x is less than 10\n";
      return;
   }

   std::cout << "x * x = " << x * x << std::endl;
}        

You can still put a return at the end of a void method/function but it's not needed.

For instance:

1
2
3
4
5
void Foo()
{

 return;
}


is valid. It just isn't worth it.
Thanks
Topic archived. No new replies allowed.