Course Content
C++ Introduction
4. Introduction to Program Flow
5. Introduction to Functions
C++ Introduction
Return Statement in Functions
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:
first_example.cpp
second_example.cpp
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
Everything was clear?
Course Content
C++ Introduction
4. Introduction to Program Flow
5. Introduction to Functions
C++ Introduction
Return Statement in Functions
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:
first_example.cpp
second_example.cpp
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
Everything was clear?