Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Return Statement in Functions | Introduction to Functions
course content

Course Content

C++ Introduction

Return Statement in FunctionsReturn 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:

cpp

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:

cpp

first_example.cpp

cpp

second_example.cpp

A lot of returns

There can be multiple returns inside functions, and each one will only fire under certain conditions.

cpp

main.cpp

If there are two returns, the second return function will be ignored:

cpp

main.cpp

What will the function return?

Select the correct answer

Everything was clear?

Section 5. Chapter 3
course content

Course Content

C++ Introduction

Return Statement in FunctionsReturn 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:

cpp

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:

cpp

first_example.cpp

cpp

second_example.cpp

A lot of returns

There can be multiple returns inside functions, and each one will only fire under certain conditions.

cpp

main.cpp

If there are two returns, the second return function will be ignored:

cpp

main.cpp

What will the function return?

Select the correct answer

Everything was clear?

Section 5. Chapter 3
some-alt