When functions have a return type other than void, the function has two new requirements:

  • There must be a value returned from the function.
  • The return value must be the same type as the function’s return type.

But where does the return value get returned to?

It gets returned to the place where the function is called. For example, if you have the following function:

std::string feed_the_cat() { return "Cat is fed!"; }

And then print the function call inside of main():

int main() { std::string cat_message = feed_the_cat(); std::cout << cat_message; }

The return value of the function is what gets printed to the terminal.


Watch how make_sandwich() passes its return value back to the function call in main().

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?