Returning from void Functions

Generally, you don't have to use an explicit return statement in a void function. The function will automatically return to the caller when the closing curly brace is reached. You may use a return statement, as long as it has no value associated with it. This is usually done when you want to return to the caller before the end of the function is reached:
void getSides(int &length, int &width)
{
  cout << "Enter length and width ";

  cin >> length;
  cin >> width;
}  

void getSides(int &length, int &width)
{
  cout << "Enter length and width ";
 
  cin >> length;
  cin >> width;

  return;
}
Previous page
Next page

Back to Lesson 6 Index
Back to Outline