Skip to Content
Learn
Functions
Return Types — Beyond the Void

When you do in fact want your function to return something and pass information back to the rest of your program, C++ has you covered. Just like there are many variable types, there are many different return types for functions.

A function can return most data types we’ve covered, including double, int, bool, char, std::string, and std::vector.

std::string always_blue() { return "blue!\n"; }

Note: The return statement is the last line of code that a function will execute. For example:

std::string always_blue() { return "blue!\n"; std::cout << "Returned blue!"; }

The final line will not execute because a value has already been returned. So "Returned blue!" won’t be printed to the terminal.

Instructions

1.

Convert needs_it_support from a void function into a bool type function.

2.

We’re currently printing support at the end of the function body.

Remove that print statement. Instead, return support from the function.

Inside of main(), print the result of needs_it_support() to the terminal.

Folder Icon

Take this course for free

Already have an account?