Returning Values from Functions

To return a single value from a function, you use the return statement at the end of the function (the type of the value being returned must match the type of the function):
int cube(int number)
{
  int someValue;

  someValue = number * number * number;

  return someValue;
}
To return more than one value from a function, you use the reference parameters that were passed in. These will carry the values back to the caller.
void getSides(int &length, int &width)
{
  cout << "Enter length and width ";

  cin >> length;
  cin >> width;
}
Previous page
Next page

Back to Lesson 6 Index
Back to Outline