Course Content
Introduction to C++
Introduction to C++
Return
The return statement terminates the execution of a function and returns a value of a predefined type.
If the type is specified incorrectly, the function will behave unpredictably:
main.cpp
That is, before creating a function, the type of data that it returns must be specified. Also, in C++, there are special void functions. Functions of this data type are allowed to return nothing:
main.cpp
or return "nothing":
main.cpp
Note
Usually, void-type functions simply display static text or work with pointers (spoilers).
A lot of returns
There can be multiple returns inside functions, and each one will only fire under certain conditions.
main.cpp
If there are two returns, the second return function will be ignored:
main.cpp
What will the function return?
Select the correct answer
Everything was clear?