Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Type of Functions | Introduction to Functions
C++ Introduction

Type of FunctionsType of Functions

When creating a function, the data type it returns always specified.

In the example of the main function, we see that it has an integer data type, which means that after it finishes its work, it will return an integer value, in our case, the number 0.

Note

Since the main function is reserved in C++, it will always return integer.

But our functions can return any value:

To call a function, you need to write its name with brackets:

cpp

main.cpp

We have created a function that returns a value of 3.14 as a double data type, and we have called this function to display its output on the screen.

Functions can also be string type:

cpp

main.cpp

The typedef is also applicable:

cpp

main.cpp

If you can't exactly specify the return type, the auto operator will force the compiler to do it for you:

cpp

main.cpp

Все було зрозуміло?

Секція 5. Розділ 2
course content

Зміст курсу

C++ Introduction

Type of FunctionsType of Functions

When creating a function, the data type it returns always specified.

In the example of the main function, we see that it has an integer data type, which means that after it finishes its work, it will return an integer value, in our case, the number 0.

Note

Since the main function is reserved in C++, it will always return integer.

But our functions can return any value:

To call a function, you need to write its name with brackets:

cpp

main.cpp

We have created a function that returns a value of 3.14 as a double data type, and we have called this function to display its output on the screen.

Functions can also be string type:

cpp

main.cpp

The typedef is also applicable:

cpp

main.cpp

If you can't exactly specify the return type, the auto operator will force the compiler to do it for you:

cpp

main.cpp

Все було зрозуміло?

Секція 5. Розділ 2
some-alt